如何监控使用的是Android SDK中的GPS适配器的状态? [英] How can I monitor the status of the GPS adapter using Android SDK?

查看:153
本文介绍了如何监控使用的是Android SDK中的GPS适配器的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的应用程序监控GPS适配器是否anabled或禁用。我不在乎在monemt或不实际的GPS功能运行 - 我需要的GPS适配器的状态

I need to have my app monitor whether the GPS adapter is anabled or disabled. I don't care about the actual GPS functionality running at the monemt or not -- I need the status of the GPS adapter.

我可以做手工BU呼吁: 字符串商= Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED)

I can manually do it bu calling : String providers = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED)

如果GPS上市,那么它的主动,否则就不是。但我找不到得到通知时,GPS已启用或用户禁用任何文件。我曾尝试使用addGpsStatusListener在LocationManager,但是当被收购的实际GPS定位,只有通知(例如,如果正在使用的地图应用程序)。

If "gps" is listed, then it's active, otherwise it's not. But I can't find any documentation on getting notified when GPS is enabled or disabled by the user. I did try to use addGpsStatusListener in LocationManager, but that only notifies when the actual GPS fix is being acquired (like if the Maps app is being used).

任何想法?

推荐答案

LocationContentObserver没关系,我找到了答案;

LocationContentObserver Nevermind, I found the answer;

getContentResolver().registerContentObserver(
    Settings.Secure.getUriFor(Settings.System.LOCATION_PROVIDERS_ALLOWED), 
            false, 
            new LocationContentObserver ( new Handler())
    );

class LocationContentObserver extends ContentObserver {
  public LocationContentObserver( Handler h ) {
    super( h );
  }

  public void onChange(boolean selfChange) {
      SendNotification(false);
  }
}

这篇关于如何监控使用的是Android SDK中的GPS适配器的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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