For my application for some functionalities, I need to use the camera, which is not required to the core functionality of the application, so I need to specify the it's optional to use camera. So in the manifest I declared the permission as follows:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
But when I try to grant permission through adb using the following command it gives an error:
pm grant my.app.package android.permission.CAMERA
gives the error:
Operation not allowed: java.lang.SecurityException: Can't change android.permission.CAMERA. It is required by the application
My device is a rooted one and it runs android 5.1.1(22). According to the ADB documentation, since the permission is declared as optional, I should be able to grant permission from adb as mentioned above. I have referenced this, this and this. But still I couldn't figure out a reason for why it's not working.
Thank you in advance for suggestions and recommendations.