如何检测,当用户打开/关闭GPS状态? [英] How to detect when user turn on/off gps state?

查看:331
本文介绍了如何检测,当用户打开/关闭GPS状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要禁止从我的application.The用户不断变化的WIFI,GPS和加载设置,用户不用开启/关闭WIFI和GPS在运行我的应用程序。(从通知栏)。是有任何的BroadcastReceiver存在听力GPS开/关?

I want to block the user from changing wifi,gps and loading settings from my application.The user need not on/off wifi and gps while running my application.(From notification bar).Is there any BroadcastReceiver exist for listening gps on/off?

在此先感谢

推荐答案

您可以听一个GpsStatus.Listener GPS状态 并与LocationManager注册。

You can listen the GPS status with a GpsStatus.Listener and register it with the LocationManager.

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.addGpsStatusListener(new android.location.GpsStatus.Listener()
{
    public void onGpsStatusChanged(int event)
    {
        switch(event)
        {
        case GPS_EVENT_STARTED:
            // do your tasks
            break;
        case GPS_EVENT_STOPPED:
            // do your tasks
            break;
        }
    }
});

您需要访问上下文(例如在活动或应用程序级)。

You need to have access to the context (for example in an "Activity" or "Application" class).

  • <一个href="https://developer.android.com/reference/android/location/GpsStatus.Listener.html">https://developer.android.com/reference/android/location/GpsStatus.Listener.html
  • <一个href="https://developer.android.com/reference/android/location/LocationManager.html">https://developer.android.com/reference/android/location/LocationManager.html
  • https://developer.android.com/reference/android/location/GpsStatus.Listener.html
  • https://developer.android.com/reference/android/location/LocationManager.html

这篇关于如何检测,当用户打开/关闭GPS状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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