Android 11 camera not working
RaviUmraliya opened this issue · 3 comments
hi, I found the solution.
In the manifest file, I updated like below, it worked very well in Android 11.
-
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" -
tools:ignore="ScopedStorage"/> -
<queries> -
<intent> -
<action android:name="android.media.action.IMAGE_CAPTURE" /> -
</intent> -
<intent> -
<action android:name="android.media.action.VIDEO_CAPTURE" /> -
</intent> -
</queries>
Let's try it.
hi, I had the solution for Android 11
I updated the lib at the function dispatchTakePictureIntent like this
fun dispatchTakePictureIntent(): Intent? {
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Ensure that there's a camera activity to handle the intent
if (Build.VERSION.SDK_INT >=29) {
filephoto = getImageFile(File(mContext.getFilesDir(), "filepicker"))
val authority =
mContext.packageName + mContext.getString(R.string.image_picker_provider_authority_suffix)
photoURI = FileProvider.getUriForFile(mContext, authority, filephoto!!)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
return takePictureIntent
} else {
if (takePictureIntent.resolveActivity(mContext.packageManager) != null) {
// Create the File where the photo should go
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
filephoto = getImageFile(File(mContext.getFilesDir(), "filepicker"))
val authority =
mContext.packageName + mContext.getString(R.string.image_picker_provider_authority_suffix)
photoURI = FileProvider.getUriForFile(mContext, authority, filephoto!!)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
} else {
filephoto = getImageFile(File(mContext.getExternalCacheDir(), "filepicker"))
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(filephoto))
}
return takePictureIntent
}
}
return null
}
It worked well in Android 11
If you want the demo, let contact me via skype: vantuan2009
un dispatchTakePictureIntent(): Intent? { val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) // Ensure that there's a camera activity to handle the intent if (Build.VERSION.SDK_INT >=29) { filephoto = getImageFile(File(mContext.getFilesDir(), "filepicker")) val authority = mContext.packageName + mContext.getString(R.string.image_picker_provider_authority_suffix) photoURI = FileProvider.getUriForFile(mContext, authority, filephoto!!) takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) return takePictureIntent
} else { if (takePictureIntent.resolveActivity(mContext.packageManager) != null) { // Create the File where the photo should go if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { filephoto = getImageFile(File(mContext.getFilesDir(), "filepicker")) val authority = mContext.packageName + mContext.getString(R.string.image_picker_provider_authority_suffix) photoURI = FileProvider.getUriForFile(mContext, authority, filephoto!!) takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) } else { filephoto = getImageFile(File(mContext.getExternalCacheDir(), "filepicker")) takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(filephoto)) } return takePictureIntent } } return null }
Hi can you share ImageCaptureManager file
