0

i am working on android app in which i want to change profile automatically from Ringing to Airplane Mode. application work fine on android 2.3 to 4.2 but don't work on 4.4 kitkat. Logcat show this error

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid

i have already add following permission

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" /> 

but same problem is occur in 4.4

error point to this code

Airplane_mode(false);

//

public void Airplane_mode(boolean isEnabled) {

        if (isEnabled) {
            Settings.System.putInt(this.getContentResolver(),
                    Settings.System.AIRPLANE_MODE_ON, 1);

            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", isEnabled);
            sendBroadcast(intent);

        } else if (!isEnabled) {
            Settings.System.putInt(this.getContentResolver(),
                    Settings.System.AIRPLANE_MODE_ON, 0);
            Settings.System.putInt(this.getContentResolver(),
                    Settings.System.AIRPLANE_MODE_RADIOS, 1);
            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", isEnabled);
            sendBroadcast(intent);
        }

    }

//

    Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intent.putExtra("state", isEnabled);
    sendBroadcast(intent);

please solve my problem thanks

Attaullah
  • 3,856
  • 3
  • 48
  • 63
  • 1
    Google has been progressively locking down these system broadcasts so apps cannot send them. This broadcast was never designed to be sent by SDK apps, and toggling airplane mode has privacy and security ramifications. [The documentation for this `Intent` action](http://developer.android.com/reference/android/content/Intent.html#ACTION_AIRPLANE_MODE_CHANGED), like many others, has: "This is a protected intent that can only be sent by the system." – CommonsWare Jun 10 '15 at 21:30
  • thanks but what is alternative solution?? – Attaullah Jun 11 '15 at 04:32
  • Hopefully, there is no alternative solution. As noted, toggling airplane mode has privacy and security ramifications. – CommonsWare Jun 11 '15 at 10:47

0 Answers0