Skip to content

Cannot open the device gallery on Android #172

@dpdragnev

Description

@dpdragnev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions