4

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

Vincent
  • 61
  • 1
  • 6
  • 1
    Welcome to SO. You shouldn't take screenshots of your code. It's possible to copy them out of the terminal. Don't be lazy, write them directly into the question. – Smittey Nov 09 '15 at 09:56
  • 1
    @Smittey Thanks. I edited my post. – Vincent Nov 09 '15 at 10:04

2 Answers2

4

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.

cuihtlauac
  • 1,808
  • 2
  • 20
  • 39
0

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

Eliran Kuta
  • 4,148
  • 3
  • 24
  • 28
  • But i only have apk file.What i am currently working on is automated-tests code.There are no onCreate method. What should i do? – Vincent Nov 09 '15 at 10:10
  • 3
    `CHANGE_CONFIGURATION` is a `signature|privileged|development` permission, it will not be granted to an application using `requestPermissions()`. – cuihtlauac Nov 14 '15 at 08:54