Android-FilePicker icon indicating copy to clipboard operation
Android-FilePicker copied to clipboard

Android 11 camera not working

Open RaviUmraliya opened this issue 4 years ago • 3 comments

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?

RaviUmraliya avatar May 04 '21 16:05 RaviUmraliya

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 avatar May 06 '21 02:05 vtuan070978

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

vtuan070978 avatar Jul 31 '21 03:07 vtuan070978

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

zeeshanrasool91 avatar Dec 22 '21 13:12 zeeshanrasool91