revoked permission android.permission.CAMERA

You should use AppCompatActivity instead, of extending your MainActivity. And also please, include stacktrace.

public class MainActivity extends AppCompatActivity {

//......
}

Oh, sorry. With stacktrace it's clearly seen main problem. android.permission.CAMERA. For making request, you should create permission check. Please, check This Example, to create Permission checking.

Example:

1) Include to Activity.

<uses-permission android:name="android.permission.CAMERA" />

2) Ensure you request permissions from the user:

if ( ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) {

            ActivityCompat.requestPermissions( this, new String[] {  android.Manifest.permission.ACCESS_COARSE_LOCATION  },
                                                LocationService.MY_PERMISSION_ACCESS_COURSE_LOCATION );
}

3) Check in RunTime

if ( Build.VERSION.SDK_INT >= 23 &&
             ContextCompat.checkSelfPermission( context, android.Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED) {
            return;
}

Revoke Permission....It Simply say's you have invoked the permission again so no need to write permission for Camera again in Manifest file ......

Instead you just....need to write two line....to READ and Write External Storage which are enough to run your program it's enough to run your program


Here's how I solved this problem.

Contrary to what most answers say, REMOVE this from your Manifest file.

 <uses-permission android:name="android.permission.CAMERA"/>

Why?

Starting Android M (API 23), if your app has CAMERA permission declared in the manifest, then, it needs that CAMERA permission to be GRANTED in order to access ACTION_IMAGE_CAPTURE etc... too (which normally do not require the CAMERA permission on their own). If not, then it automatically raises a SecurityException.

╔═════════════════════════════════════════════════╦════════════════════╗
║                      Usage                      ║ Permissions needed ║
╠═════════════════════════════════════════════════╬════════════════════╣
║ ACTION_IMAGE_CAPTURE                            ║ none               ║
║ ACTION_VIDEO_CAPTURE                            ║ none               ║
║ INTENT_ACTION_STILL_IMAGE_CAMERA                ║ none               ║
║ android.hardware.camera2                        ║ CAMERA             ║
║ android.hardware.camera2 + ACTION_IMAGE_CAPTURE ║ CAMERA             ║
║ android.hardware.camera2 + ACTION_VIDEO_CAPTURE ║ CAMERA             ║
║ ...                                             ║ ...                ║
╚═════════════════════════════════════════════════╩════════════════════╝

Above table is only for API 23+

tl;dr What to do?

Option 1- If you only use ACTION_IMAGE_CAPTURE etc...
Remove the CAMERA permission from manifest and you would be fine

Option 2- If you use other CAMERA functions:
Check for CAMERA permission at runtime and only start the intent when the permission is available


Hi lunatique aldebaran,

First of all you need to add the following permission in manifest.xml file.

<uses-permission android:name="android.permission.CAMERA" />

Check whether the android device is Marshmallow or not. If its android M or greater version then use the following code to get camera permission dynamically.

Before android M dont want to get dynamic permission.

check if the user grant the permission. If user not granted permission then request the camera permission access.

private static final int MY_CAMERA_REQUEST_CODE = 100;
if (checkSelfPermission(Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {
           requestPermissions(new String[]{Manifest.permission.CAMERA},
                        MY_CAMERA_REQUEST_CODE);
            }

After requesting the permission alert will display to ask permission contains allow and deny options. After clicking action we can get result of the request with the following method.

@Override

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode == MY_CAMERA_REQUEST_CODE) {

            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();

            } else {

                Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();

            }

        }

Tags:

Android