Android GPS以编程方式打开/关闭

时间:2016-01-23 09:50:47

标签: android

如何打开和关闭GPS卫星(图标),我不是在寻找这个

// automatic turn off the gps
public void turnGPSOff()
{
    String provider = Settings.Secure.getString(ctx.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"));
        this.ctx.sendBroadcast(poke);
    }
}

这只能禁用GPS卫星搜索,但不能关闭GPS图标

2 个答案:

答案 0 :(得分:1)

图标由任何应用是否正在积极使用GPS(例如,已为requestLocationUpdates()调用GPS_PROVIDER)控制。我们欢迎您控制应用程序使用GPS,但您无法通过应用程序影响该图标。

答案 1 :(得分:-1)

昨天试试这项工作

 //Enable GPS
 Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
 intent.putExtra("enabled", true);
 sendBroadcast(intent);
//Disable GPS
 Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
 intent.putExtra("enabled", false);
 sendBroadcast(intent);

参考链接Answer

相关问题