【问题标题】:BroadcastReceiver for Google Play Location Service (setting of the Status Bar)Google Play Location Service 的 BroadcastReceiver(状态栏的设置)
【发布时间】:2015-04-03 20:11:34
【问题描述】:

我正在尝试注册 BroadcastReceiver 以获取 Location 设置的状态更改

但我没有找到任何文档。我只找到BroadcastReceiver 来检查某些搜索提供程序的状态(GPS 和Network providers);但不适用于检查此特定选项 (Location) 在系统偏好设置中是否处于活动状态。

谁能告诉我正确的方向?


注意:

我使用了 Google Play 定位服务(com.google.android.gms.location.LocationListener 界面)。

【问题讨论】:

标签: android geolocation broadcastreceiver google-play-services android-settings


【解决方案1】:

好吧,我找到了一种方法来检查action bar 的“Location”设置是启用还是禁用;但是没有BroadcastReceiver(真遗憾)

private static final String TAG = getClass().getName();

/* We define the LocationManager */
LocationManager location_Manager= (LocationManager) getSystemService(LOCATION_SERVICE);

/* If the GPS provider or the network provider are enabled; the Location setting is enabled.*/
if(location_Manager.isProviderEnabled(LocationManager.GPS_PROVIDER) || location_Manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
    Log.d(TAG, "The Location setting is enabled");
}else{
   /* We send the user to the "Location activity" to enable the setting */
   Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
   startActivity(intent);
}

我真的不需要BroadcastReceiver;因为拥有我的应用程序的“架构”让我可以不用它;但我很想知道如何使用它。

注意:

如果有人找到BroadcastReceiver 的方法,我会用她的答案更改我的正确答案。

【讨论】:

    【解决方案2】:

    您可以尝试使用位置监听器。

    onProviderDisabled(字符串提供程序)
    当提供程序被用户禁用时调用。

    与提供者字符串比较,例如
    provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER) http://developer.android.com/reference/android/location/LocationListener.html

    【讨论】:

    • 嗨,范雄。我现在无法测试您的答案,但我会在几个小时内尝试,然后,如果有效,我会接受您的答案。但看起来还不错,+1
    • 我尝试使用你的答案中的信息,但不幸的是,我在这个项目中使用了import com.google.android.gms.location.LocationListener,所以我无法访问android.location.LocationListener接口的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 2016-05-07
    相关资源
    最近更新 更多