I am working with Camera Intent. Everything is working fine till Android 10, but in Android 11 I am getting result Code 0.
Manifest Permission
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Intent function with file creation :
private void openCameraApp() { Intent picIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE). addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); try { String file_path = Environment.getExternalStorageDirectory().toString() + "/" + mContext.getResources().getString(R.string.app_name); File dir = new File(file_path); if (!dir.exists()) dir.mkdirs(); imagePath = new File(dir, mContext.getResources().getString(R.string.app_name) + System.currentTimeMillis() + ".png"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { picIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID, imagePath)); setUri(FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID, imagePath)); } else { picIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imagePath)); setUri(Uri.fromFile(imagePath)); } ((Activity) mContext).startActivityForResult(picIntent, CAMERA_REQUEST); } catch (Exception e) { logger.e(e); } }
I have added android:requestLegacyExternalStorage="true"
in application tag of manifest file.
See intent.resolveActivity returns null in API 30. Maybe there is something wrong with AndroidManifest.
Or see Cannot take a photo programmatically on Android 11 - intent returns canceled status.