0

Actually i used my distributors and retailers GPS location in my app when they start their meeting and GPS will not turn off until they do not end their meeting as i have to take their end meeting location . But this cause a battery problem in their phones . Is there any way to turn off GPS Automatically between their start meeting and End meeting?

Sean A.
  • 652
  • 5
  • 9

2 Answers2

0

I don't think that it is now possible to programmatically turn GPS ON/OFF. This feature was available in earlier android versions, but i think now google has stopped it. Instead, you can direct the user to GPS settings page so that the user can himself make the choice whether he wants to expose his location or not. You can do this by calling:

startActivity(context, new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

A lot of people these days are skeptical regarding sharing their location, that's why the consent of users is mandatory for sending GPS location.

Kaveesh Kanwal
  • 1,753
  • 17
  • 16
  • Just a comment, on people being skeptical of sharing location, a better solution then just blanket disabling it period. Disable it, but allow a setting where a user that might be willing to let an app turn it on and off can go and give permission to that app. Those of use that might want to let this happen on 1 or 2 apps that we trust (or we wrote) can still have access to a useful feature, instead of throwing the baby out with the bathwater. – mpop Mar 11 '18 at 22:02
0

You can use this

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);
}}private void turnGPSOff(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(provider.contains("gps")){ //if gps is enabled
    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);
}}

call this when you want to disable gps or enable it when you required, more you can find from How can I enable or disable the GPS programmatically on Android?

Community
  • 1
  • 1
antoniomerlin
  • 521
  • 1
  • 7
  • 17