Android Question [SOLVED] Does CheckAndRequest open a dialog for you ?

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
I am referring to this post : https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/

As I understand it, CheckAndRequest would open the dialog we see when an app needs some dangerous permissions (listed). But some dangerous permissions don't open the confirmation dialog.

Manifest (I tried to declare and not declare - code below)
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddPermission("android.PERMISSION_RECORD_AUDIO")

Paths
path.png


Code (project attached)
B4X:
#Region  Project Attributes 
    #ApplicationLabel: CheckPermissions
    #VersionCode: 1
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private RP As RuntimePermissions
    Private AR As AudioRecordApp 'for testing only (Thought we needed something to force the permission)...
    Dim PS As PhoneSensors
End Sub

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

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    If FirstTime Then
        AR.Initialize("AR")
        PS.Initialize(21) 'TYPE_HEART_RATE
    End If
   
    CheckPermissions
End Sub

Sub Activity_Resume
    PS.StartListening("PS")
    PS.StopListening
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub CheckPermissions
   
    RP.CheckAndRequest(RP.PERMISSION_RECORD_AUDIO)

End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    Log($"Permission: ${Permission}
Result: ${Result}"$)
   
    Select Permission
        Case RP.PERMISSION_RECORD_AUDIO
            CheckCheck(RP.PERMISSION_ACCESS_FINE_LOCATION)
        Case RP.PERMISSION_ACCESS_FINE_LOCATION
            CheckCheck(RP.PERMISSION_BODY_SENSORS)
        Case RP.PERMISSION_BODY_SENSORS
            CheckCheck(RP.PERMISSION_WRITE_EXTERNAL_STORAGE) 'this one works
    End Select
End Sub

Sub CheckCheck(What As String)
    RP.CheckAndRequest(What)
End Sub

Permissions detected by B4A
permb4a.png


Project attached if you would like to try
 

Attachments

  • CheckPermissionsEX.zip
    6.5 KB · Views: 339

lemonisdead

Well-Known Member
Licensed User
Longtime User
Thanks for the correction (I did copy the RuntimePermissions constant instead of the permission).

But does it mean that we have to still declare the permission in the Manifest ? For example the Sensor is not set in the Manifest, I use it in the code and request the permission but it does not show the dialog.
Edit: read this and we don't have to add anything in the Manifest https://b4x.com/android/forum/threads/help-with-run-time-permissions.68247/#post-432643

But why is the Sensor permission not listed in the "List Permissions", please ?
If I comment the Permission: android.permission.RECORD_AUDIO in the Manifest, it is not listed too
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top