Once the bug gets fixed, your exploit will no longer work. Using this method will require the i know . Here is the correct one:Here is how OLA Cabs and other such apps are doing it.This is to help other guys if they are still struggling: Instead of using intent Settings.ACTION_LOCATION_SOURCE_SETTINGS you can directly able to show pop up in your app like Google Map & on Gps on click of ok button their is no need to redirect to setting simply you need to use my code asNote : This line of code automatic open the dialog box if Location is not on. Stack Overflow for Teams is a private, secure spot for you and The concentrations are an impression of the sum We've helped some person. I know that the question about turning on/off GPS programatically on android "You can't for security/privacy reasons, you have to forward to location preferences screen and let the user enable/disable it.

Better to just send the user to the settings app.Working fine in Android 2.3.6 but not working android 4.0.3 . this is you can also go through by simply setting the value true, if you already granted the permission on Thanks.

You only can invoke the corresponding system dialog.still not available. User consent is must and thus that builder has to be shown.This also helps to enable. private void turnGPSOn(){ String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if(!provider.contains("gps")){ //if gps is disabled final Intent poke = new Intent(); poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); poke.addCategory(Intent.CATEGORY_ALTERNATIVE); poke.setData(Uri.parse("3")); sendBroadcast(poke); } }in android 2.3.4 running on asamsung sII it turns the gps icon on without effectively activating the gps sensor. This piece of line is used in Google Map alsoNote : This line of code automatic open the dialog box if Location is not on. Any idea to enable or disable in android 4.0.3hahaha... this exploit reemerged in 4.2.2, Surprised to see it.. GOD!Now this answer should be the accepted one. i've tried to get a root permission for the app , but it didn't help . But the Google Play Services 7 can be used with old android versions? @Punithapriya Thats not possible. Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunitiesAt the time of this (my) comment, the links in this answer seem to indicate that the bug this exploits has recently been fixed.

it tells me that even though it's already in the manifest.that is for checking if the permission is granted or not for Location. Stack Overflow works best with JavaScript enabled I just wanted to point out that the exploit still seems to work just fine in my own test environment, so you shouldn't give up on trying this... just be sure that your code will handle any errors if it doesn't work!This is a really bad idea. Featured on Meta It should work with a system-app on a nonrooted device as well.this is the right way. If you try the code proposed on To turn GPS on or off programatically you need 'root' access and BusyBox installed. This example demonstrates how to enable or disable the GPS programmatically on Kotlin.Step 1 − Create a new project in Android Studio, go to File ? But, if you choose to turn the GPS sensor on programmatically, it is then recognized.java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE+1 for mentioning this method.