Unresolved reference: READ_MEDIA_IMAGES
Asked Answered
P

2

8

I started targeting Android 13 with API 33. The app is requesting Manifest.permission.READ_EXTERNAL_STORAGE for the older APIs. Now I know that I have to request the new permissions: READ_MEDIA_IMAGES and READ_MEDIA_VIDEO. I have added in the manifest:

    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

and now, as a result, in the setting of the permissions for the app I see an extra option to enable these permissions. What I can't do is to ask the permission at runtime If I try to access Manifest.permission.READ_MEDIA_IMAGES in the code I get unresolved reference so I can't dynamically request the permission and if I don't then the user needs to do it manually.

How to handle the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO?

Pallor answered 15/12, 2022 at 13:41 Comment(5)
Set your compile version in build gradle on 33. If you already have that then update some implementation's.Orthoclase
I'm doing it alreadyPallor
Did you solve this? I have the same problem, also compiling and targeting 33Claudetta
Nevermind, it was just me changing to compile against api 33 in the wrong gradle file. :/Claudetta
I had to uninstall and reinstall the app after changing the targetSdk to get the runtime permission prompt displayed, even though I had denied the old permission. Note: I didn't have "Unresolved reference", just the permission prompt problem.Limbic
H
1

According to official documentation https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions, you should ask permission in runtime. Also notice:

Note: If your app only needs to access images, photos, and videos, consider using the photo picker instead of declaring the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO permissions.

Housebroken answered 15/12, 2022 at 13:46 Comment(3)
That's the problem. I didn't manage to ask the permission at runtimt because the constants are unresolved even if I'm targeting API 33Pallor
import android.ManifestDibbell
import android.Manifest made the difference :·)Parr
A
0

Inside the code use

android.Manifest.permission.READ_MEDIA_IMAGES

rather than

Manifest.permission.READ_MEDIA_IMAGES
Acute answered 1/8 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.