我在管理一个应用程序的工作wifi
联系,这个问题我已经在android 6.0
该wifi
扫描时关闭位置服务被用户关闭。
我想知道的是,当用户关闭然后再打开时,是否有可以订阅的动作可以收听location services
。我在 Android 文档中搜索过,有两种可能的操作,但我不确定要使用哪一种。
动作是
android.location.PROVIDERS_CHANGED
android.location.MODE_CHANGED
文档对我没有帮助。
当用户想要触发打开/关闭位置提供的任何操作时,这很有用
您应该在清单中添加此操作
<action android:name="android.location.PROVIDERS_CHANGED" />
添加此操作后,您可以触发广播接收器
<receiver android:name=".GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
在你的BroadcastReceiver
班级中,你必须LocationListener
在下面给出的那个班级中实现..
public class GpsLocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
Toast.makeText(context, "in android.location.PROVIDERS_CHANGED",
Toast.LENGTH_SHORT).show();
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if( !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
//NO GPS
}else{
//Gps is on
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句