apache / cordova-plugin-media-capture

Apache Cordova Media Capture Plugin
https://cordova.apache.org/
Apache License 2.0
307 stars 489 forks source link

Android permission denied When opening the camera #261

Closed tamsel12 closed 1 year ago

tamsel12 commented 1 year ago

I have updated the SDK version 32 in Android application and Updated the plugin too.

Before It works fine , It captures the image and video fine. Now After Upgrading SDK version, Camera not opened and it throws as "Permission Denied" error.

What is expected to happen?

After Upgrading the version 32 cordova-android 11 , it should open camera

What does actually happen?

Camera not opening, It throws Permission Denied error {"code":4,"message":"Permission denied."} vendor-es2015.js:41296 ERROR Error: Uncaught (in promise): Object: {"code":4,"message":"Permission denied."} at resolvePromise (polyfills-es2015.js:3904:39) at resolvePromise (polyfills-es2015.js:3856:21) at polyfills-es2015.js:3966:21 at ZoneDelegate.invokeTask (polyfills-es2015.js:3505:35) at Object.onInvokeTask (vendor-es2015.js:64523:33) at ZoneDelegate.invokeTask (polyfills-es2015.js:3504:40) at Zone.runTask (polyfills-es2015.js:3273:51) at drainMicroTaskQueue (polyfills-es2015.js:3675:39)

Information

Updated the Cordova-android 10 to cordova-android 11 which targets 32

Command or Code

ionic cordova run android --device

Environment, Platform, Device

This issue in Android Device [Checked in Android 10, Android 11, Android 12]

Version information

Android version [10,11,12] Cordova-android 11[sdk -32] Mediacapture plugin 4.0.0

Checklist

tamsel12 commented 1 year ago

Any Solutions? We want to upload the Build with targetSDKLevel 32 within October to playstore. From november onwards playstore will only accept the SDK Level above 30. This plugin works fine in Android SDK 30 [Cordova-android-10]

breautek commented 1 year ago

Android has the capability of automatically rejecting permissions if the user has previously "Denied Always" permission in the past and this information can survive app uninstalls/reinstalls. In which case, the user must change permissions using the Android App settings.

Are you certain this isn't the case of a permission being denied always? On AOSP emulators, you can reset this state using adb shell pm reset-permissions which is useful for testing. You'll need to have $ANDROID_HOME/platform-tools in your PATH to use the adb command.

Note that this command will reset permissions on *all* applications back to their default "Not requested" state for all permissions, but I don't think this command is available on Google android images (images with the playstore) or real devices.

tamsel12 commented 1 year ago

@breautek I have not run on Emulator, I tested in Android device , the same version is working fine on SDK 30 level on Android Devices , But after upgrading to 32 [cordova-android 11] only , this permission issue arises.

tamsel12 commented 1 year ago

This issue arises when using Mediacapture plugin with latest instabug-cordova plugin. I have checked media capture plugin alone, it opens the camera and it works fine but with latest Instabug-cordova plugin only its throwing the permission denied error

tamsel12 commented 1 year ago

Actually Below fixes the problem -- Remove instabug-cordova and readd the plugin -- Update in Android manifest file

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"

-- Update

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourpackage" xmlns:tools="http://schemas.android.com/tools">

Now its working fine for me, I will close this issue 
FrancescoPaiola commented 11 months ago

Why this problem?

I'm using ionic 6 (capacitor 5) and i've faced this problem due to Android 13 permissions changes.

What I've done?

I've found e temporary solutions for those who needs only a working captureVideo() method as me. Check out the fork here: https://github.com/SocialCities/cordova-plugin-video-capture

Basically I've added a version check method to support Android 13 (SDK >= 33) permissions changes as you can see here: https://github.com/apache/cordova-plugin-media-capture/compare/master...SocialCities:cordova-plugin-video-capture:master. In particular I've added READ_MEDIA_VIDEO permission requirement dynamically if SDK is >= 33).

How to install?

// uninstall cordova-plugin-media-capture
npm uninstall cordova-plugin-media-capture
// install my fork
npm install https://github.com/SocialCities/cordova-plugin-video-capture.git

// if it's not already done:
npm install @awesome-cordova-plugins/media-capture 
ionic cap sync

Attention

This solutions is incomplete. Plugin's methods other than captureVideo() should not works correctly, because i have an upcoming work deadline and I need only that method. If you need the other plugin's methods too, you need to extend my function and manage the other permissions requirements for version SDK >= 33 (READ_MEDIA_IMAGES and READ_MEDIA_AUDIO) based on what needed.

Hope this fork can be useful for those who need a temporary solution like me 😺!

shivamsharmanps commented 10 months ago

I tried with your fork I am getting class not found an error in android API 31.

FrancescoPaiola commented 10 months ago

I'm using API 33 ionic 6 (capacitor 5). With API 31 you will probably have problems on every device with Android 13 (due to Android 13 permissions changes).

TheSynt4x commented 10 months ago

I am using Ionic 7 and I get the canceled issue right after accepting the permission to use camera. Any workaround or anyone else knows what this is caused by?

DUWENINK commented 10 months ago

I tried with your fork I am getting class not found an error in android API 31.

me too ,can had you sloved it?