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

Cannot open the device gallery on Android #172

Open
dpdragnev opened this issue Dec 23, 2023 · 1 comment
Open

Cannot open the device gallery on Android #172

dpdragnev opened this issue Dec 23, 2023 · 1 comment

Comments

@dpdragnev
Copy link

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
Copy link
Author

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.

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

1 participant