Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn on Location Providers Programmatically in Android

Is it possible to turn on LocationProviders(GPS Provider/Network Providers) on Device programatically, if it is turned off?

like image 610
Prem Singh Bist Avatar asked Jan 24 '12 08:01

Prem Singh Bist


4 Answers

No, it is not, but you can open the Location services settings window:

context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
like image 51
Rotemmiz Avatar answered Nov 16 '22 19:11

Rotemmiz


Enabling Location with mode High Accuracy or Battery saving without user needing to visit Settings

https://android-developers.googleblog.com/2015/03/google-play-services-70-places-everyone.html

like image 23
Akhil Dad Avatar answered Nov 16 '22 18:11

Akhil Dad


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);
}
}

But this code support only upto APK 8.

like image 39
mob_web_dev Avatar answered Nov 16 '22 17:11

mob_web_dev


Yes but you have to be a Super User (sudo), Your device must be rooted.

like image 1
Kishore Avatar answered Nov 16 '22 19:11

Kishore