I have to disable AIRPLANE MODE and DATE TIME SETTINGS in my app, for that i used these intent filters but
TLDR: Don't do that.
Think what happens if user couldn't enable airplane mode though if they want/should.
Important system settings cannot allowed to change from your app.
I recommend:
EDIT: it looks like this:
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void checkAirplaneMode() {
int mode;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Log.v(TAG, "work with new api.");
mode = Settings.Global.getInt(getActivity().getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0);
} else {
Log.v(TAG, "work with old api.");
mode = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0);
}
Log.v(TAG, "airplane mode: " + mode);
if(mode == 1 /* airplane mode is on */) {
new AlertDialog.Builder(getActivity()).setTitle("Sorry!")
.setMessage("This app doesn't work with Airplane mode.\n"
+ "Please disable Airplane mode.\n")
.setPositiveButton("Open Settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS));
getActivity().finish();
}
})
.setNegativeButton("Close app", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getActivity().finish();
}
})
.show();
}
}
here's some point.
Build.VERSION.SDK_INT to use Settings.Global for newer devices. Airplane mode is moved to here. startActivity(new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS));As for version 4.2 and up you are not able to control the Airplane mode programmatically.
You are able to do so only if the user has a rooted device.
As written in the API DOC:
"Some device settings defined by Settings.System are now read-only. If your app attempts to write changes to settings defined in Settings.System that have moved to Settings.Global, the write operation will silently fail when running on Android 4.2 and higher.
Even if your value for android:targetSdkVersion and android:minSdkVersion is lower than 17, your app is not able to modify the settings that have moved to Settings.Global when running on Android 4.2 and higher."