ON / OFF开关在Android手机检测GPS [英] Detecting GPS on/off switch in Android phones

查看:196
本文介绍了ON / OFF开关在Android手机检测GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当用户更改或关闭GPS设置为Android手机来检测。 当用户经由访问点切换的GPS sattelite开/关或检测含义等

I would like to detect when the user changes the GPS settings on or off for an Android phone. Meaning when user switches GPS sattelite on/off or detection via access points etc.

推荐答案

当我发现做到这一点的最好办法是将附加到

As I have found out the best way to do this is to attach to the

<action android:name="android.location.PROVIDERS_CHANGED" />

意图。

例如:

<receiver android:name=".gps.GpsLocationReceiver">
        <intent-filter>
            <action android:name="android.location.PROVIDERS_CHANGED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

然后在code:

And then in the code:

public class GpsLocationReceiver extends BroadcastReceiver implements LocationListener 
...

@Override
public void onReceive(Context context, Intent intent)
{
        if (intent.getAction().matches("android.location.PROVIDERS_CHANGED"))
        { 
            // react on GPS provider change action 
        }
}

这篇关于ON / OFF开关在Android手机检测GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆