ParaCamera icon indicating copy to clipboard operation
ParaCamera copied to clipboard

java.lang.IllegalAccessException: Unable to open camera in Emulator Android 11

Open spungkyb opened this issue 5 years ago • 1 comments

java.lang.IllegalAccessException: Unable to open camera i can open camera, how solve this?

spungkyb avatar Nov 02 '20 04:11 spungkyb

i have this issue, it depends on SdkVersion not your android version, if its more than 29 , this library doesn't work

compileSdk 29

defaultConfig {
    targetSdk 29
  }

so how fix it on new sdks :

you must download the code and copy it to your poroject and in class Camera comment this codes and run your project successfully

public void takePicture() throws NullPointerException, IllegalAccessException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); switch (mode) { case ACTIVITY: // if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { setUpIntent(takePictureIntent); activity.startActivityForResult(takePictureIntent,REQUEST_TAKE_PHOTO); // } else { // throw new IllegalAccessException("Unable to open camera"); // }

or change to this

public void takePicture() throws NullPointerException, IllegalAccessException {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    switch (mode) {
        case ACTIVITY:
            try {
                setUpIntent(takePictureIntent);
                activity.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            }catch (Exception ex){
                  throw new IllegalAccessException("Unable to open camera");
             }
        
            break;

hamidsamirabad avatar Dec 23 '21 13:12 hamidsamirabad