Android Question Problems with the permissions

francesco paolo lavecchia

Member
Licensed User
Hi all,
I don't know why rp.CheckAndRequest(Permission) works for

Permissions.Add(rp.PERMISSION_READ_EXTERNAL_STORAGE)
Permissions.Add(rp.PERMISSION_ACCESS_FINE_LOCATION)

and doesn't work for

Permissions.Add(rp.PERMISSION_READ_PHONE_STATE)
Permissions.Add(rp.PERMISSION_CALL_PHONE)

I mean this,

upload_2019-6-29_17-25-17.png









B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

Dim rp As RuntimePermissions
Dim numPermission As Int
Dim noPermission As Int
Dim Permissions As List

End Sub

Sub Activity_Create(FirstTime As Boolean)

Dim i As Int
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")

   Permissions.Initialize
   Permissions.Add(rp.PERMISSION_READ_PHONE_STATE)
   Permissions.Add(rp.PERMISSION_CALL_PHONE)
   Permissions.Add(rp.PERMISSION_READ_EXTERNAL_STORAGE)
   Permissions.Add(rp.PERMISSION_ACCESS_FINE_LOCATION)

   numPermission = 0
   noPermission = 0
   Do While (numPermission < (Permissions.Size-1))
       For i=0 To Permissions.Size-1
           Dim Permission As String = Permissions.Get(i)
           If Not(rp.Check(Permission)) Then
               rp.CheckAndRequest(Permission)
               Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
               If Result Then
                   numPermission = numPermission + 1
                   noPermission = noPermission - 1
               Else
                   noPermission = noPermission + 1
                   Msgbox("No Permission: " & Permission,Application.LabelName)
                   If noPermission = (Permissions.Size) Then
                       ExitApplication
                   End If
               End If
           End If
       Next
   Loop

   Msgbox("Ok",Application.LabelName)

End Sub

Thanks in advance
 

francesco paolo lavecchia

Member
Licensed User
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

AddPermission(android.PERMISSION_READ_PHONE_STATE)
AddPermission(android.Permissions_CALL_PHONE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.ACCESS_FINE_LOCATION)
 
Upvote 0

francesco paolo lavecchia

Member
Licensed User
I also made a little video...

You have to change
PERMISSION1 in permission.z01
PERMISSION2 in permission.z02
PERMISSION3 in permission.z03

(extensions z01,z02,z03 are not allowed)
 
Last edited by a moderator:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Code with Msgbox is not considered valid code. You should never use modal dialogs. Use MsgboxAsync instead.
2. This code is much simpler: https://www.b4x.com/android/forum/threads/handle-multiple-permission-request.94611/#post-598788
3. First step is to click on the List Permissions button (Logs tab):

B4A_d7BlnxjtgB.png


You can immediately see that there are only two "dangerous" permissions.
The other two that should be marked with an asterisk are not marked because the permission case is incorrect.
 
Upvote 0

francesco paolo lavecchia

Member
Licensed User
Sorry but I don't understand
You are saying not to use msgbox, ok, but the the problem is different:

the code doesn't stop on:

rp.CheckAndRequest(READ_PHONE_STATE)
rp.CheckAndRequest(CALL_PHONE)

so the user can't answer to any request

This thing doesn't happen for

rp.CheckAndRequest(READ_EXTERNAL_STORAGE)
rp.CheckAndRequest(ACCESS_FINE_LOCATION)

I tried any options but the problem is always the same.

What do you mean with: First step is to click on the List Permissions button?

upload_2019-7-1_8-58-40.png
 
Upvote 0
Top