【问题标题】:How to programatically turn off GPS in andoid? [duplicate]如何以编程方式在android中关闭GPS? [复制]
【发布时间】:2021-08-01 00:37:28
【问题描述】:

我知道这是一个经常被问到的问题。但是我能找到的所有答案都很古老,所以我想再问一次。

我想以编程方式关闭手机上的 GPS 服务。对此的最新答案是什么?

提前致谢。

【问题讨论】:

标签: android android-location android-gps


【解决方案1】:

使用此代码关闭 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);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多