如何检测,当用户打开/关闭GPS状态?状态、用户、GPS

由网友(和好不如初)分享简介:我要禁止从我的application.The用户不断变化的WIFI,GPS和加载设置,用户不用开启/关闭WIFI和GPS在运行我的应用程序。(从通知栏)。是有任何的BroadcastReceiver存在听力GPS开/关?I want to block the user from changing wifi,gps a...

我要禁止从我的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).

https://developer.android.com/reference/android/location/GpsStatus.Listener.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
阅读全文

相关推荐

最新文章