Reputation: 1
We all know about that GPS Issues on Android.
How do we create the same turnOnGps Function Bellow to a NETWORK_PROVIDER, I want turn on Both.
private void turnGPSOn(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){
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);
} }
Upvotes: 0
Views: 1947
Reputation: 992
Just adding onto what CommonsWare mentioned, that method only works on Android versions of 2.2 and below.
However, you can use the, simple, code below:
startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
This will take the user directly to the screen where they can enable/disable Location based options.
Refer here (docs), for more settings
Hope this helps
Upvotes: 1
Reputation: 1006539
Fortunately, the script-kiddie technique you cite above does not work on modern versions of Android. You cannot enable or disable any location provider yourself, for blindingly obvious privacy reasons. Please allow the user to enable or disable location providers through the OS-supplied mechanisms (Settings, Power Control app widget, etc.).
Upvotes: 0