BroadcastReceiver for Google Play位置服务(状态栏的设置)

时间:2015-02-04 10:33:11

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

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

Location settings

但我没有找到任何文件来做这件事。我只找到BroadcastReceiver来检查某些搜索提供商的状态( GPSNetwork providers );但不能检查系统首选项中此特定选项(Location)是否处于活动状态。

有人可以告诉我正确的方向吗?


  

注意:

     

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

2 个答案:

答案 0 :(得分:1)

好吧,我找到了一种方法来检查Location的“action bar”设置是启用还是禁用;但没有一个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;因为拥有我的应用程序的“ arquitecture ”允许我不用它;但我本来想知道如何使用它。

  

<强>注意:

     

如果有人找到了使用BroadcastReceiver的方法,我将通过她的答案更改我的正确答案。

答案 1 :(得分:1)

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

  

onProviderDisabled(String provider)
  用户禁用提供程序时调用。

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