I have troube to use Airplane mode on my app. The app runs perfectly well on my emulator but not in my real phone when I try my apk.
Here is the code to activate the Airplane :
Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);
// Post an intent to reload
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
// send a broadcast
//intent.putExtra("state", !isEnabled);
intent.putExtra("state", true);
sendBroadcast(intent);
To desactivate it :
Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
// Post an intent to reload
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
// send a broadcast
intent.putExtra("state", false);
sendBroadcast(intent);
I read that I cannot create the intent (android doc) but I saw people that could make airplane mode so I don't understand!
Thanks to help me !
As you stated, the answer is in the documentation:
"This is a protected intent that can only be sent by the system."
Intent Documentation Reference
It may work on an emulator because the emulator isn't a secured device and lets you do things (like browse the file system) that you wouldn't normally be able to do. Also, you didn't mention what API level of Android you are trying to use. If it is something current, Google might have tightened down the restriction.