的Android关闭GPS
答
尝试......
locationManager.removeUpdates(myLocationListener); locationManager = null;
答
我认为作为一种安全措施,android系统不会允许您打开和关闭用户的gps(因为我认为是android 2.0) 。你可以停止获取更新,并且应该停止使用gps(除非其他应用程序使用它),或者要求用户将其关闭。
答
可以停止监听在你的应用GPS的事件(如果您的应用程序使用GPS)。例如,使用LocationManager.removeUpdates
,例如 。
如果你想“关闭”在操作系统级别的GPS,我认为这是不可能的编程方式。
答
你,(用面包也许)要求用户要做到这一点,开始本次活动
if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER))
{
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
}
答
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);
}
}
这是什么会做什么? – user533844
这应该启动用户可以禁用GPS的设置屏幕。 – Reno
哦确定.....好主意.... – user533844