Android设备GPS /关闭编程设备、Android、GPS

2023-09-12 21:38:38 作者:姐不妖怎能独领风骚

我使用下面的code上的GPS /关闭。

I am using following code for GPS on/off.

//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。    我使用上述code为。但它并没有在所有设备上工作。    请帮我。在此先感谢。

Programatically I need to on/off GPS on android device. I am using above code for that. But It doesn't work on all the devices. Please help me. Thanks In advance.

推荐答案

从我个人的经验,我回答这个问题,

From my personal experience, I am answering this,

您在您的问题已停止从Android 4.4系统版本的工作给出的黑客$​​ C $ C。您会触发此异常来自奇巧版本开始 java.lang.SecurityException异常:权限被拒绝:不允许发送广播android.location.GPS_ENABLED_CHANGE

第一回答的code将无法工作了,它只显示动画GPS在通知栏图标。

The First answer's code will not work any more, it only display animated GPS icon in notification bar.

有关的保障目的,谷歌开发了上述两种方法,它们分别为previously做工精细块。

For The security purpose Google developer has block above both methods which were previously working fine.

因此​​结论是,你不能以编程方式启动GPS开启或关闭。

Hence conclusion is that You can not programmatically start GPS On or Off.