Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 11 camera not working #325

Open
RaviUmraliya opened this issue May 4, 2021 · 3 comments
Open

Android 11 camera not working #325

RaviUmraliya opened this issue May 4, 2021 · 3 comments

Comments

@RaviUmraliya
Copy link

RaviUmraliya commented May 4, 2021

device-2021-05-04-213222

When I click on the camera icon in Android 11 camera not open and showing the toast shown above image.
Is there anything that needs to update in the code?

@vtuan070978
Copy link

vtuan070978 commented May 6, 2021

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.

@vtuan070978
Copy link

vtuan070978 commented Jul 31, 2021

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

@zeeshanrasool91
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants