我没想到问题在哪里? 我应该写一些东西到Manifest来启用这个功能吗?
private void toggleGPS(boolean enable) {
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps") == enable) {
return; // the GPS is already in the requested state
}
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"));
context.sendBroadcast(poke);
}`
答案 0 :(得分:0)
是的,您需要在android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
答案 1 :(得分:0)
您可以在Android Manifest.xml中添加不同的权限,以获取您可能需要以下内容的位置:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />