简单,一个广播搞定
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION);
intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION);
context.registerReceiverAsUser(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (LocationManager.MODE_CHANGED_ACTION.equals(action)) {
locationSettingsChanged();
}
}
}, UserHandle.ALL, intentFilter, null, new Handler());