Vincent
Vincent

Reputation: 61

Android grant permission error

I got this error when i was going to grant CHANGE_CONFIGURATION permission to my application:(is Windows platform)

CMD command line error is below:

/$ pm grant packageName android.permission.CHANGE_CONFIGURATION >

operation not allowed: java.lang.SecurityException: Package packageName has not requested permission android.permission.CHANGE_CONFIGURATION

Anyone know how to solve this?

Thanks

Upvotes: 4

Views: 7355

Answers (2)

cuihtlauac
cuihtlauac

Reputation: 1878

Have you requested CHANGE_CONFIGURATION in your Manifest?

<uses-permission android:name="android.permission.CHANGE_CONFIGURATION">    

Which device and version of Android are you using? I've tested the pm grant command on a Nexus 6 using Android 6 (MRA58N), it worked.

Upvotes: 4

Eliran Kuta
Eliran Kuta

Reputation: 4348

You have to request the permission to be granted.

inside OnCreate method of your main activity:

// New permissions model test
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
    if (checkSelfPermission(Manifest.permission.CHANGE_CONFIGURATION) != PackageManager.PERMISSION_GRANTED)
    {
        String [] permissions = new String[1];
        permissions[0] = Manifest.permission.CHANGE_CONFIGURATION;

        requestPermissions(permissions, 7001);
    }
}

And override this in your activity:

@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if(grantResults[0] == 0)    // Permission was granted
        yourJob.start();    
}

Of course, declare it in the manifest.xml as well

Upvotes: 0

Related Questions