I would like to switch the GPS status in my application. The method I know is to modify the secure setting of device like the following code
Settings.Secure.putString(resolver, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, newAllowedProviders);
However, modifying secure setting is only available in the full rooted devices. If not, it will throw exceptions, even I have add this permission in the AndroidManifest.xml
.
java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
Recently, I discovery an open source application "Quick settings" is able to do it on an non full rooted device, however the author did not release t开发者_如何学运维he code of this part. The reason is that he is using some kind of android exploits, he is not willing to release it.
Does any body know how he achieve it?
The method that quick settings released is the same method above (modify the security setting). It works, but only in the full rooted device.
However, the real method that quick setting currently used is not released in it's source code, which could work on both root and unroot phone.
The source for Quick Setting is available. You may want to build it agains API level 6. I build it agains 7 and gps toggle will not work. Let us know if you can build for 6 and see that it work on 7 or later.
精彩评论