Android Question CheckAndRequest

Sergey_New

Well-Known Member
Licensed User
Longtime User
Android(14) SDK: 34
I want to use the READ_MEDIA_IMAGES permission.
B4X:
rp.CheckAndRequest(rp.PERMISSION_READ_MEDIA_IMAGES)
When entering the code, an error occurs due to the lack of this constant.
Please tell me what to do?
 

drgottjr

Expert
Licensed User
Longtime User
you need to use the string version "android.permission.READ_MEDIA_IMAGES"
 
Upvote 0
Solution

Sergey_New

Well-Known Member
Licensed User
Longtime User
I have it stated in my manifest
B4X:
AddPermission(android.permission.READ_MEDIA_IMAGES)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the thread says check and request. nothing about manifest.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I probably described my problem poorly. When entering the code, there is no PERMISSION_READ_MEDIA_IMAGES item in the drop-down list.
1.png
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I probably described my problem poorly. When entering the code, there is no PERMISSION_READ_MEDIA_IMAGES item in the drop-down list.
View attachment 162151
As drgottjr said at post#2, you need to use the string version
B4X:
rp.CheckAndRequest( "android.permission.READ_MEDIA_IMAGES")
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
teddybear, drgottjr thanks!
Now it's clear. Where can I read about it?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
here:
it's simply a variable like any other with a value. the permission names are just strings. when you make a library and you want to let users refer to variables in the library, you declare them public.

when erel wrote the runtime permissions library, he made a number of permission names public. for example, the camera permission:
public static final String PERMISSION_CAMERA = "android.permission.CAMERA";

when you want to check for a permission, you can use the names that are public. you can also use the string value of the variable. it's a convenience. it saves time because most of the permissions that we use are declared public. you don't have to remember the exact wording of some string.

if android adds a new permission, it does not exist in the runtime permissions library until the library is updated and the new permission is defined and made public. you have to go to android documentation and find where the permission is defined in the sdk.

in the library, the check and request method passes a string: public void CheckAndRequest(BA ba, String Permission)

in the runtime permissions library if the public variable is defined, you can use it. if it's not defined (in the library), you can use the string value as defined in the sdk.
note: you have to use the string version in the manifest. the manifest has nothing to do with the library.
 
Upvote 0
Top