I'm using imported Scalibrary module sample app for image processing filter. It has two main button open camera and open gallery.
It's working fine on android Kitkat but when I try to launch the camera on android 9 It crash
I have tried adding : android:requestLegacyExternalStorage="true"
on manifest but no luck
Note : I have already given permission camera and external write read storage on manifest
Update : Apparently I have to make the permission pop up for it to works because Im currently enabling it manually in the settings how do I do that ?
What Im I missing ?
Stacktrace
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.documentscanner/com.scanlibrary.ScanActivity}: java.lang.
SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.
CaptureActivity clip={text/uri-list U:content://com.scanlibrary.provider/external_files/scanSample/IMG_20191230_065113.jpg} (has extras) } from
ProcessRecord{6bafaa3 13455:com.example.documentscanner/u0a140} (pid=13455, uid=10140) with revoked permission android.permission.CAMERA
Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.
camera2/com.android.camera.CaptureActivity clip={text/uri-list U:content://com.scanlibrary.provider/external_files/scanSample/IMG_20191230_065113.jpg} (has extras) } from ProcessRecord{6bafaa3 13455:com.example.documentscanner/u0a140} (pid=13455, uid=10140) with revoked permission android.permission.CAMERA
at com.scanlibrary.PickImageFragment.openCamera(PickImageFragment.java:129)
at com.scanlibrary.PickImageFragment.handleIntentPreference(PickImageFragment.java:77)
at com.scanlibrary.PickImageFragment.init(PickImageFragment.java:58)
at com.scanlibrary.PickImageFragment.onCreateView(PickImageFragment.java:48)
PickImageFragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.pick_image_fragment, null);
init();
return view;
}
private void init() {
cameraButton = (ImageButton) view.findViewById(R.id.cameraButton);
cameraButton.setOnClickListener(new CameraButtonClickListener());
if (isIntentPreferenceSet()) {
handleIntentPreference();
} else {
getActivity().finish();
}
}
private void handleIntentPreference() {
int preference = getIntentPreference();
if (preference == ScanConstants.OPEN_CAMERA) {
openCamera();
} else if (preference == ScanConstants.OPEN_MEDIA) {
openMediaContent();
}
}
public void openCamera() {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file = createImageFile();
boolean isDirectoryCreated = file.getParentFile().mkdirs();
Log.d("", "openCamera: isDirectoryCreated: " + isDirectoryCreated);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri tempFileUri = FileProvider.getUriForFile(getActivity().getApplicationContext(),
"com.scanlibrary.provider", // As defined in Manifest
file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
} else {
Uri tempFileUri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
}
startActivityForResult(cameraIntent, ScanConstants.START_CAMERA_REQUEST_CODE);
}