NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
187 stars 104 forks source link

[@nativescript/camera][android] Fails to take photo on Android 12 & 11 #546

Closed PeterStaev closed 7 months ago

PeterStaev commented 8 months ago

I'm having the following code:

import {
    isAvailable,
    requestPermissions,
    takePicture,
} from "@nativescript/camera";

await requestPermissions();

const requestedSize = Utils.layout.toDeviceIndependentPixels(1024);
return takePicture({
    saveToGallery: false,
    cameraFacing: "rear",
    width: requestedSize,
    height: requestedSize,
});

This works fine on Android 13 but not on Android 12 & 11. When the code is executed I correctly get a prompt to allow camera access. When I allow it the requestPermissions() fails with the following error:

  {
    "android.permission.WRITE_EXTERNAL_STORAGE": false,
    "android.permission.CAMERA": true
  }

May be this function should be changed to check for API30 and not API33? https://github.com/NativeScript/plugins/blob/91d0b298ba00c42731346b2291e668c6bc43c66e/packages/camera/index.android.ts#L171-L173C2

PeterStaev commented 8 months ago

Actually testing for Andoird 11 it also fails with the same error. On Android 9 it works fine though.

PeterStaev commented 8 months ago

According to this: https://developer.android.com/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE the external storage permission is effective only up to and including Android 10.

Also according to this: https://developer.android.com/guide/topics/media/camera the WRITE_EXTERNAL_STORAGE should be requested only if targeting API29 or lower.

So probably the method should be changed to check for API 29 and not 33.