Created
January 9, 2014 05:53
-
-
Save songzhiyong/8329998 to your computer and use it in GitHub Desktop.
Turn on or turn off the gps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void turnGPSOn() | |
{ | |
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); | |
intent.putExtra("enabled", true); | |
this.ctx.sendBroadcast(intent); | |
String provider = Settings.Secure.getString(ctx.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")); | |
this.ctx.sendBroadcast(poke); | |
} | |
} | |
// automatic turn off the gps | |
public void turnGPSOff() | |
{ | |
String provider = Settings.Secure.getString(ctx.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")); | |
this.ctx.sendBroadcast(poke); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment