ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
534 stars 599 forks source link

@capacitor/camera - Android "Selected Photos Access" #2150

Open julienkermarec opened 4 months ago

julienkermarec commented 4 months ago

Feature Request

Plugin

@capacitor/camera

Description

Android 14 introduces Selected Photos Access, which allows users to grant apps access to specific images and videos in their library, rather than granting access to all media of a given type.

Capture d’écran 2024-07-11 à 11 05 11

This change is only enabled if your app targets Android 14 (API level 34) or higher. If you don't use the photo picker yet, we recommend implementing it in your app to provide a consistent experience for selecting images and videos that also enhances user privacy without having to request any storage permissions.

If you maintain your own gallery picker using storage permissions and need to maintain full control over your implementation, adapt your implementation to use the new READ_MEDIA_VISUAL_USER_SELECTED permission. If your app doesn't use the new permission, the system runs your app in a compatibility mode.

Platform(s)

Android

Preferred Solution

Implement the new way to request permission & picture selection

Alternatives

No other plugins alternative

Additional Context

New Permission to add

<!-- To handle the reselection within the app on devices running Android 14 or higher if your app targets Android 14 (API level 34) or higher.  -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

New requesting permission :

// Register ActivityResult handler
val requestPermissions = registerForActivityResult(RequestMultiplePermissions()) { results ->
    // Handle permission requests results
    // See the permission example in the Android platform samples: https://github.com/android/platform-samples
}

// Permission request logic
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
    requestPermissions.launch(arrayOf(READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_MEDIA_VISUAL_USER_SELECTED))
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    requestPermissions.launch(arrayOf(READ_MEDIA_IMAGES, READ_MEDIA_VIDEO))
} else {
    requestPermissions.launch(arrayOf(READ_EXTERNAL_STORAGE))
}
M13CZ commented 3 months ago

Is there aby workaround for this before it will be fixed on plugin side?

julienkermarec commented 3 months ago

Is there aby workaround for this before it will be fixed on plugin side?

Yes, on can use @capacitor/filesystem for selecting private photo

For using camera, you need to continue using @capacitor/camera