Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在运行时检查位置设置更改_Java_Android_Google Maps_Geolocation - Fatal编程技术网

Java 在运行时检查位置设置更改

Java 在运行时检查位置设置更改,java,android,google-maps,geolocation,Java,Android,Google Maps,Geolocation,我使用基本的位置更新行为来获取用户位置,如中所述 它工作得很好,但我被一些看似简单的东西困住了: 我如何知道用户在应用程序运行时是否禁用了他的位置? 我可以在启动活动时使用检查是否启用了位置,但在运行时如何执行此操作?有一个广播: 代码类似于: private final IntentFilter filter = new IntentFilter(LocationManager.MODE_CHANGED_ACTION); private final BroadcastRe

我使用基本的位置更新行为来获取用户位置,如中所述

它工作得很好,但我被一些看似简单的东西困住了:

我如何知道用户在应用程序运行时是否禁用了他的位置?


我可以在启动活动时使用检查是否启用了位置,但在运行时如何执行此操作?

有一个广播:

代码类似于:

private final IntentFilter filter =
          new IntentFilter(LocationManager.MODE_CHANGED_ACTION);

private final BroadcastReceiver receiver = new BroadcastReceiver() {
   @Override public void onReceive(Context context, Intent intent) {
       if(LocationManager.MODE_CHANGED_ACTION.equals(intent.getAction()) {
            // check here the new location status
       }
   }
};

// then to register
context.registerReceiver(receiver, filter);
/// and unregister
context.unregisterReceiver(receiver);

有这样一个广播:

代码类似于:

private final IntentFilter filter =
          new IntentFilter(LocationManager.MODE_CHANGED_ACTION);

private final BroadcastReceiver receiver = new BroadcastReceiver() {
   @Override public void onReceive(Context context, Intent intent) {
       if(LocationManager.MODE_CHANGED_ACTION.equals(intent.getAction()) {
            // check here the new location status
       }
   }
};

// then to register
context.registerReceiver(receiver, filter);
/// and unregister
context.unregisterReceiver(receiver);

完美的我只需要在请求位置更新时注册此BroadcastReceiver,并在活动终止时注销它。谢谢完美的我只需要在请求位置更新时注册此BroadcastReceiver,并在活动终止时注销它。谢谢