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

0

There are 0 answers