nativescript-camera-plus icon indicating copy to clipboard operation
nativescript-camera-plus copied to clipboard

Cannot open the device gallery on Android

Open dpdragnev opened this issue 1 year ago • 1 comments

Hello, here is my setup:

...
<!-- Devices running Android 12L (API level 32) or lower  -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- Devices running Android 13 (API level 33) or higher -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <!-- To handle the reselection within the app on Android 14 (API level 34) -->
    <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
    <uses-permission android:name="android.permission.CAMERA" />
...

When the user opens the camera, a popup asking for permission to access the camera appears, and after the user accepts, they can use the camera. However, when they try to access the gallery (the popup to allow access shows up and it is accepted), I see the following message in the console:

NativeScript-CameraPlus --- [disposeNativeView.]

At this point, the camera closes and nothing happens.

Here is my code:

export function pickImageFromGallery() {
    if (!cam)  cam = new CameraPlus();

    cam.galleryPickerMode = 'single';

    if (isAndroid) {
        if (!cam.hasStoragePermissions()) {
            cam.requestStoragePermissions().then((response: boolean) => {
                if (response) {
                    doPickFromGallery();
                }
            });
        } else {
            doPickFromGallery();
        }
    } else {
        doPickFromGallery(); // iOS
    }
}

function doPickFromGallery() {
    cam.chooseFromLibrary().then((imageAssets: any) => {
       console.log('image passed back: ', imageAssets);
       ... rest of the code
    });
}

This happens on a simulator (Pixel 7, API 33) as well as on a physical device (Samsung Note 9, Android 10, API 30).

Any help in resolving this would be greatly appreciated.

dpdragnev avatar Dec 23 '23 13:12 dpdragnev

I spent a few days trying to fix this issue without success, so I switched to https://github.com/NativeScript/plugins/tree/main/packages/imagepicker#nativescriptimagepicker. I just replaced the chooseFromLibrary() method with the corresponding method from the ImagePicker plugin.

dpdragnev avatar Dec 26 '23 21:12 dpdragnev