Android Question Handle multiple permission request

Shay

Well-Known Member
Licensed User
Longtime User
I have in my app multiple permission requests, such as:
rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
rp.CheckAndRequest(rp.PERMISSION_READ_CALL_LOG)
rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)

I wish that app will start only if the above will approve (since no point opening the app without it)
what is the best way to handle such
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
You could possibly use this:

B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
   If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
     gmap.MyLocationEnabled = Result
   ELSE
        ' Credit for the following code to DonManfred
         rs= Msgbox2("You have not given permission - I can not proceed"    ,"Permission Failure","Yes","Cancel","No",Null)
        If rs=DialogResponse.POSITIVE Then
             StopService(Starter)
            Activity.Finish
            ExitApplication
            Return True ' RETURN TRUE to consume the Event---
   End If
End Sub

Example discussion here https://www.b4x.com/android/forum/threads/app-not-closing.92401/#post-584361

I have not tested - but I have faith that it will work.

Enjoy !!
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
Multiple If Statements.

Process --> Check and Request --> Permission Result --> If statement --> Return --> Check next permission --> Repeat Process.

Let's presume you have 3 permissions.

Check the first one - user accepts - so it's OK

Check the second one - user accepts - so it's OK

Check the third one - user does NOT accept - so app does not execute.

Enjoy !!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Edit: don't put this code in Activity_Resume. Request the permissions right before you need them.
Activity_Resume can be called multiple times during the requests and it can cause some requests to fail.

B4X:
Sub Activity_Resume
   For Each permission As String In Array(rp.PERMISSION_READ_CONTACTS, rp.PERMISSION_READ_CALL_LOG, rp.PERMISSION_CALL_PHONE)
       rp.CheckAndRequest(permission)
       Wait For Activity_PermissionResult (permission As String, Result As Boolean)
       If Result = False Then
           ToastMessageShow("No permission!", True)
           Activity.Finish
           Return
       End If
   Next
   'we have permission!
End Sub
 
Last edited:
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
Great thanks, b.t.w I saw app's that created layout just for the permissions as first screen, which I think good approach
 
Upvote 0
Top