The whole function to achieve the idea is very clear, just change the system configuration (system.airplane_mode_on), send a notification can be. But discovering that Android's permissions are not as open as it used to be. Starting with Android 4.2 (SDK API 17), these properties are read-only, and the official web site says:
Some device settings defined by Settings.system are now read-only. If your app attempts to write changes to settings defined in Settings.system then have moved to Settings.global, the write Operation'll silently fail when running on Android 4.2 and higher.
So for Android4.2 and above version of the mobile phone is a tragedy ~
Just start in the code to try to modify the properties of system.airplane_mode_on, the UI seems to have no reflection, log saw that the lack of Android.permission.WRITE_SECURE_SETTINGS permissions, In manifest declaration, eclipse compiles but prompts Permission is only system Apps, saying that it must be a system application. There are also a variety of solutions to discuss on the web, such as the application of the system, the need for a package with the firmware to compile or the same signature as the firmware. It is also said that it can be achieved by reflection. The first way should be very troublesome, get under a certain source code package ah, and the second scheme some people say can try, but I did not try ~ do not know whether it is reliable.
Later on, or from the Internet to find a solution, but device must be root, otherwise no way to fix. The original text from here, although do not know which country language ~ But the code is still known.
Open Flight mode
Settings put global airplane_mode_on 1
Am BROADCAST-A Android.intent.action.AIRPLANE_MODE--ez State True
Turn off flight mode.
Settings put global airplane_mode_on 0
Am Broadcast-a Android.intent.action.AIRPLANE_MODE--ez State false
Through the ADB shell, enter the above two commands, you can switch flight mode. The core problem solved ~ The rest is to use Java code to invoke the shell command, this is not difficult ~ but must be aware of the need to call through root, in addition to prevent the program card dead ~
The solution was also mentioned later in StackOverflow, and another solution was to change the Android system configuration directly through SQLite. Database location in/data/data/com.android.providers.settings/databases/settings.db
Sqlite3/data/data/com.android.providers.settings/databases/settings.db
INSERT into global values (null, ' airplane_mode_on ', 1); Insert the corresponding 0 value, that is, cancel flight mode
Of course, the above database changes to be effective, or must be issued above the broadcast to be effective.
The following is the interface of the applet I wrote:
Use the following methods:
Set the time to open and close the flight mode respectively, the default is 12:30 A.M. Open flight mode, the morning 7 point off flight mode. Then open the current state of the button, you will be prompted the next time to switch flight mode.
After the set time, app will automatically try to enable the flight mode state, as shown in the second image above, of course it should be allowed (preferably added to the list of trusted programs, or each frame). In addition, after the set time, it is possible that you are still using the phone and do not want to switch flight mode immediately, the app will give you 5s of time to consider, 5 seconds after you do not operate, the app will automatically enable flight mode. Of course, after you cancel, this time will not be switched, but when you press the phone to return the key (the home key does not) or kill the process and then restart the app, will be based on the time set to meet the rules automatically switch.
Switch "off" state is to cancel the setting function, if the current mobile phone is in flight mode state, will also switch to normal state.
Note: For Android4.2 and above, the cell phone needs root only OK, and it is recommended to add to the list of trusted programs. The version before 4.2 was a problem with wood.
Welcome students interested in downloading 1 Download 2 trial, suggestions/comments Welcome Feedback ~
Todo:
The unification of the Android versions of the UI style
Add more than one time period setting, support to sleep at night and sleep at noon turn flight mode, both save electricity and prevent disturb
There should be a lot of bugs when you're writing a blind game.