我需要一些編程的事件後關閉GPS,我使用下面的方法,但我不能夠做到這一點......如何以編程方式在android手機中禁用GPS?
private void turnGPSOff(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){
final Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
intent.setData(Uri.parse("3"));
sendBroadcast(intent);
Toast.makeText(getBaseContext(), "GPS Turned off..!", Toast.LENGTH_LONG).show();
}
}
轉到我的回答:[http://stackoverflow.com/questions/20740365/programmatically-turn-on-gps-in-android/20740483#20740483](http://stackoverflow.com/questions/20740365 /以編程方式打開gps-in-android/20740483#20740483) –
@MD ya,但始終保持GPS消耗電池電量,所以我想這樣做.. –