【发布时间】:2021-08-01 00:37:28
【问题描述】:
我知道这是一个经常被问到的问题。但是我能找到的所有答案都很古老,所以我想再问一次。
我想以编程方式关闭手机上的 GPS 服务。对此的最新答案是什么?
提前致谢。
【问题讨论】:
标签: android android-location android-gps
我知道这是一个经常被问到的问题。但是我能找到的所有答案都很古老,所以我想再问一次。
我想以编程方式关闭手机上的 GPS 服务。对此的最新答案是什么?
提前致谢。
【问题讨论】:
标签: android android-location android-gps
使用此代码关闭 GPS
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);
}
【讨论】: