Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
224 views
Welcome To Ask or Share your Answers For Others

1 Answer

You CANNOT broadcast a System level intent. This is illegal by android's standards.

Instead of trying to send the intent, why don't you just implement a broadcast reciever to listen to that specific action and then when it changes, have your application handle it. This would be a much better approach. You cannot and should NOT expect to control airplane mode, but your app can listen to when it is invoked. You can also retrieve a property from the System database that tells you if its in airplane mode.

Once again Do not focus on trying to control it, just handle it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...