I am trying to update an app that was based on the old Bluetooth example so may not take advantage of all the latest developments in program structure. I do not write programs for B4A very often as I mostly have to use Embedded C or design electronics. My apps are used to support our embedded systems in the field.
This app needs to support Android 6+ Runtime permissions. The appropriate tutorial has an example of using RuntimePermissions.CheckandRequest() in conjunction with Wait For but does not illustrate setting multiples, and the technique doesn't work because my app runs into a run time error (from code foollowing the call to PermissionsTake1 that accesses the external storage) before the permissions dialog is even displayed. This is the sub PermissionsTake1.
I tried changing to the technique using PermissionsTake2 and a resumable Sub MyPermission so I could call MyPermission with the Resumable Subs Tutorial's Wait For () Complete (Result as boolean).
In neither case do the permissions dialogs get a chance to run but I cannot see how to restructure my program not to read the ini file in Activity_Create or shortly thereafter.
This app needs to support Android 6+ Runtime permissions. The appropriate tutorial has an example of using RuntimePermissions.CheckandRequest() in conjunction with Wait For but does not illustrate setting multiples, and the technique doesn't work because my app runs into a run time error (from code foollowing the call to PermissionsTake1 that accesses the external storage) before the permissions dialog is even displayed. This is the sub PermissionsTake1.
I tried changing to the technique using PermissionsTake2 and a resumable Sub MyPermission so I could call MyPermission with the Resumable Subs Tutorial's Wait For () Complete (Result as boolean).
In neither case do the permissions dialogs get a chance to run but I cannot see how to restructure my program not to read the ini file in Activity_Create or shortly thereafter.
B4X:
Sub PermissionsTake1
' 22-07-2019 access dangerous permissions for Android 6+
Log ("Checking PERMISSION_WRITE_EXTERNAL_STORAGE")
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Log ("Finished checking PERMISSION_WRITE_EXTERNAL_STORAGE")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_WRITE_EXTERNAL_STORAGE", True)
ExitApplication
End If
Log ("Checking PERMISSION_ACCESS_COARSE_LOCATION")
rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Log ("Finished checking PERMISSION_ACCESS_COARSE_LOCATION")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_ACCESS_COARSE_LOCATION", True)
ExitApplication
End If
Log ("Checking PERMISSION_ACCESS_FINE_LOCATION")
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Log ("Finished checking PERMISSION_ACCESS_FINE_LOCATION")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_ACCESS_FINE_LOCATION", True)
ExitApplication
Else
PermissionsDone = True
End If
End Sub
Sub PermissionsTake2
Log ("Checking PERMISSION_WRITE_EXTERNAL_STORAGE")
Wait For (MyPermission(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)) Complete (Result As Boolean)
Log ("Finished checking PERMISSION_WRITE_EXTERNAL_STORAGE")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_WRITE_EXTERNAL_STORAGE", True)
ExitApplication
End If
Log ("Checking PERMISSION_ACCESS_COARSE_LOCATION")
Wait For (MyPermission(rp.PERMISSION_ACCESS_COARSE_LOCATION)) Complete (Result As Boolean)
Log ("Finished checking PERMISSION_ACCESS_COARSE_LOCATION")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_ACCESS_COARSE_LOCATION", True)
ExitApplication
End If
Log ("Checking PERMISSION_ACCESS_FINE_LOCATION")
Wait For (MyPermission(rp.PERMISSION_ACCESS_FINE_LOCATION)) Complete (Result As Boolean)
Log ("Finished checking PERMISSION_ACCESS_FINE_LOCATION")
If Result = False Then
ToastMessageShow("Unable to set up PERMISSION_ACCESS_FINE_LOCATION", True)
ExitApplication
End If
End Sub
' in theory we can make a blocking call To this by Wait For OnePermission(rp.PermName) Complete (Result As Boolean)
Sub MyPermission(Permname As String) As ResumableSub
Log("++MyPermission")
rp.CheckAndRequest(Permname)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Log("--MyPermission")
Return Result
End Sub