Quick Setting for android development, one-click wifi shutdown, mobile network shutdown, battery setting, flight mode,

Source: Internet
Author: User

The Android underlying layer provides excellent control capabilities for both software and hardware systems, and the interface definition is very clear. We can easily implement the desired control, as a result, a quick setup function is available in the project recently, which requires one-click wifi shutdown, mobile network shutdown, battery setting, and flight mode, one-click Application Opening (the application was originally opened with one click), one-click dialing ........................ Various features, so after a week of hard work, this function has initially completed coding and testing, accidentally improved, at least used, haha, the first write this, the architecture is not fully considered, I will continue to improve later. In this article, I will post several pieces of code to implement the function. because too many interfaces are used, it is inconvenient to write a blog. I compress the package and open source code. You can download the desired shoes and code them with pure hands. I. Enable and disable automatic brightness [java] <span style = "font-size: 14px;">? �� Brightness automatically adjusted ** @ param activity */public void startAutoBrightness (Activity activity) {Settings. system. putInt (activity. getContentResolver (), Settings. system. SCREEN_BRIGHTNESS_MODE, Settings. system. SCREEN_BRIGHTNESS_MODE_AUTOMATIC);}/*** stop automatic brightness adjustment */public void stopAutoBrightness (Activity activity) {Settings. system. putInt (activity. getContentResolver (), Settings. system. SCREEN_BRIGHTNESS_MODE, Setti Ngs. system. SCREEN_BRIGHTNESS_MODE_MANUAL) ;}</span> 2. enable or disable the flight mode [java <span style = "font-size: 14px; ">/*** enable and disable flight mode */public void OpenAirplane (Context context, ImageView childImageView) {boolean isEnabled = Settings. system. getInt (context. getContentResolver (), Settings. system. AIRPLANE_MODE_ON, 0) = 1; if (isEnabled) {Settings. system. putInt (context. getContentResolver (), Settings. system. AIRPLANE_MOD E_ON, 0); childImageView. setImageDrawable (getResources (). getDrawable (R. drawable. action_airplane_off_default);} else if (! IsEnabled) {Settings. system. putInt (context. getContentResolver (), Settings. system. AIRPLANE_MODE_ON, 1); childImageView. setImageDrawable (getResources (). getDrawable (R. drawable. action_airplane_default);} Intent I = new Intent (Intent. ACTION_AIRPLANE_MODE_CHANGED); I. putExtra ("state ",! IsEnabled); context. sendBroadcast (I) ;}</span> 3: Bluetooth [java] <span style = "font-size: 14px; ">/*** enable or disable Bluetooth **/public void OpenorCloseBluetooth (Context context, ImageView childImageView) {export thadapter adapter = export thadapter. getdefaadapter adapter (); if (adapter. isEnabled () {adapter. disable (); // disable Bluetooth childImageView. setImageDrawable (getResources (). getDrawable (R. drawable. action_effecth_off_defau Lt); Toast. makeText (QuickSettingActivity. this, getString (R. string. close_bluetooth), Toast. LENGTH_SHORT ). show ();} else {adapter. enable (); // enable Bluetooth childImageView. setImageDrawable (getResources (). getDrawable (R. drawable. action_effecth_default); Toast. makeText (QuickSettingActivity. this, getString (R. string. open_bluetooth), Toast. LENGTH_SHORT ). show () ;}</span> and paste the required permissions [html] <span style = "fo Nt-size: 14px; "> <! -- One-click access to wifi --> <uses-permission android: name = "android. permission. ACCESS_WIFI_STATE "/> <uses-permission android: name =" android. permission. CHANGE_WIFI_STATE "/> <uses-permission android: name =" android. permission. WAKE_LOCK "/> <! -- Set the screen brightness --> <uses-permission android: name = "android. permission. WRITE_SETTINGS"/> <! -- Set Bluetooth --> <uses-permission android: name = "android. permission. BLUETOOTH "/> <uses-permission android: name =" android. permission. export th_admin "/> <! -- Set Vibration --> <uses-permission android: name = "android. permission. VIBRATE "/> <uses-permission android: name =" com. sec. android. app. factorymode. permission. KEYSTRING "/> <! -- Call the camera flashlight --> <uses-permission android: name = "android. permission. CAMERA "/> <uses-feature android: name =" android. hardware. camera "/> <uses-permission android: name =" android. permission. FLASHLIGHT "/> <uses-permission android: name =" android. permission. WAKE_LOCK "/> <! -- Change Network --> <uses-permission android: name = "android. permission. CHANGE_NETWORK_STATE"/> <! -- GPS --> <uses-permission android: name = "android. permission. there are too many ACCESS_FINE_LOCATION "/> </span>. For the moment, you can go to the source code if it is useful to everyone. During the development process, it is important to note that, as the sdk version is upgraded, some system setting interfaces have changed and some adjustments are required. This is also closely related to system settings, when pulling system services And data, try And catch them in time to prevent errors.: Http://download.csdn.net/user/beiminglei. Because it is the code deducted from the project, relatively messy, if you are interested in the experience of a relatively complete version, you can try our project, https://play.google.com/store/apps/details? Id = com. launcher. GTlauncher2 & feature = search_result #? T = w251bgwsmswxldesimnvbs5syxvuy2hlci5hvgxhdw5jarvymijd.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.