我正在使用以下代码来打开/关闭 GPS。
//Enable GPS
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
context.sendBroadcast(intent);
//Disable GPS
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", false);
context.sendBroadcast(intent);
我需要以编程方式在 Android 设备上打开/关闭 GPS。
我正在使用上面的代码。但它并不适用于所有设备。
以我个人的经历来回答这个问题
您在问题中显示的黑客代码已从 Android 版本 4.4 起停止工作。从 Kitkat 版本开始,您将触发此异常java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE
首先answer的代码将不再起作用,它只会在通知栏中显示动画 GPS 图标。
出于安全目的,谷歌开发人员已经阻止了这两种以前工作正常的方法。
因此,结论是您无法以编程方式启动或关闭 GPS。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)