Android Question Issue with runtimepermission

Hirogens

Active Member
Licensed User
Longtime User
Hello I try to make a runtimepermission class to ask the user some permissions. When I'm in debug mode I have no problem but when I release my application is blocked. This is my code
B4X:
Private RTP As RunTimePermission

RTP.Initialize
    wait for (RTP.manager_RunTimePermission) Complete (Resultat As Boolean)
this part is in the main at the beginning

and this is my class
B4X:
Sub Class_Globals
    Private RunTimePermissions As RuntimePermissions
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub

Sub manager_RunTimePermission As ResumableSub
    Dim counter As Int

    wait for (RTP_Write_External_Storage) complete (Resultat As Boolean)
    If Resultat = True Then
        Log("counter = 1")
        counter = counter + 1
    Else
            Log("ntm")
    End If
    
    Sleep(1500)

    wait for (RTP_Read_External_Storage) complete (Resulta As Boolean)
    If Resulta = True Then
        Log("counter = 2")
        counter = counter + 1
    Else
        Log("ntm")
    End If

    Sleep(1500)

    wait for (RTP_Coarse_Location) complete (Result As Boolean)
    If Result = True Then
        Log("counter = 3")
        counter = counter + 1
    Else
        Log("ntm")
    End If

    Sleep(1500)

    wait for (RTP_Fine_Location) complete (Resul As Boolean)
    If Resul = True Then
        Log("counter = 4")
        counter = counter + 1
    Else
        Log("ntm")
    End If

    Sleep(1500)

    wait for (RTP_Phone_Phone_State) complete (Resu As Boolean)
        If Resu = True Then
        Log("counter = 5")
        counter = counter + 1
    Else
        Log("ntm")
    End If

    If counter = 5 Then
        Return True
    Else
        Return False
    End If
    
End Sub

Private Sub RTP_Write_External_Storage As ResumableSub
    RunTimePermissions.CheckAndRequest(RunTimePermissions.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission...", True)
        Return False
    Else
        Return True
    End If

End Sub

Private Sub RTP_Read_External_Storage As ResumableSub
    RunTimePermissions.CheckAndRequest(RunTimePermissions.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission...", True)
        Return False
    Else
        Return True
    End If
'    Return True
End Sub

Private Sub RTP_Coarse_Location As ResumableSub
    RunTimePermissions.CheckAndRequest(RunTimePermissions.PERMISSION_ACCESS_COARSE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission...", True)
        Return False
    Else
        Return True
    End If
'    Return True
End Sub

Private Sub RTP_Fine_Location As ResumableSub
    RunTimePermissions.CheckAndRequest(RunTimePermissions.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission...", True)
        Return False
    Else
        Return True
    End If
'    Return True
End Sub

Private Sub RTP_Phone_Phone_State As ResumableSub
    RunTimePermissions.CheckAndRequest(RunTimePermissions.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission...", True)
        Return False
    Else
        Return True
    End If
'    Return True
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    Log(Permission & " = " & Result)
    If Result = False Then
        Log("False")
        ExitApplication
    End If
    
    Log(Permission & " = " & Result)
End Sub
 

Hirogens

Active Member
Licensed User
Longtime User
This is a small project with all the code. I would like to check some permission and after create a real time tracker. Some issue with my permission and real time tracker, but question by question ahaha
 

Attachments

  • Tester.zip
    12.2 KB · Views: 124
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
I would like for the runtime class check permission per permission and see what the user decide. If he refuse 1 permission I want to kill the application for avoid future troubles..
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
I recommend you to remove this class. It doesn't really add anything and will only make your program more complicated.

It is very simple to check for multiple permissions.

Example: https://www.b4x.com/android/forum/threads/handle-multiple-permission-request.94611/#post-598788
B4X:
    For Each permission As String In Array(rp.PERMISSION_WRITE_EXTERNAL_STORAGE, rp.PERMISSION_READ_EXTERNAL_STORAGE, rp.PERMISSION_ACCESS_COARSE_LOCATION, rp.PERMISSION_ACCESS_FINE_LOCATION, rp.PERMISSION_ACCESS_FINE_LOCATION)
        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
I look at this. But I need to implement Activity_PermissionResult (permission As String, Result As Boolean) in my code too ? Because this code already get the False event
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top