これにより、ユーザーはオン/オフの任意のアクションをトリガーしたい場合場所が
を提供して便利ですこの操作をマニフェストに追加する必要があります
<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
}
}
}
}
の可能性のある重複[ブロードキャストレシーバ/またはブロードキャストレシーバのデータ転送のためのサービスでGPS位置を取得する](http://stackoverflow.com/questions/7709030/get-gps-location-in-a-broadcast-receiver-or-service-to-broadcast -receiver-data-t) –
[How to?場所の設定がオンになっている(Android App)を聞く](http://stackoverflow.com/questions/36325088/how-to-listen-for-location-setting-being-turned-on-android-app) – maciekjanusz