java.lang.IllegalAccessException: Unable to open camera in Emulator Android 11
java.lang.IllegalAccessException: Unable to open camera i can open camera, how solve this?
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;