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 a legal Android application, you cannot do any of what you are trying to do, including moving the phone into the airplane mode, disabling radios, turning off sound or anything of that sort.
Imagine how you, a user, would feel if some arbitrary application turned off your phone radio and you miss that call which informs you that you won a million dollars.
So what everyone is trying to get to, is that you as an application should not expect to move the phone into airplane mode. Only the user can do that.
Now if the user changes into the airplane mode, the system broadcasts an Intent, your application should catch that broadcast Intent and act on it. Acting on it means a variety of things, which include changing your UI.
Even if you find someway to achieve what you are trying to do today, the system can change tomorrow without warning (since it's an internal API/Intent) and your application will not function. It might, technically, not function on any other device except the one that you hold in your hand, you know the whole API contracts crap.