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 !
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…