在Android中禁用GPS

时间:2019-11-20 13:45:19

标签: android gps android-gps

如何在android中自动关闭GPS。我尝试下面的代码,但这在android 8.0及更高版本的android 8.0中不起作用

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);
    }
}

0 个答案:

没有答案
相关问题