Android Question [SOLVED] - Starter.rp.CheckAndRequest is not calling the Request Permission dialog screen

rleiman

Well-Known Member
Licensed User
Greetings,

I'm using the following code to get the READ_PHONE_STATE permission from the user, but the Request Permission screen is never called. Do I need to add anything to the manifest editor?

B4X:
    If Starter.rp.Check(Starter.rp.PERMISSION_READ_PHONE_STATE) = False Then
        Sleep(100)
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_PHONE_STATE)
        Wait For Activity_PermissionResult (permission As String, Result As Boolean)
        Log(permission)
        If Result = False Then
            MsgboxAsync("The app asked for permission to read the phone state. This permission is " & _
                "needed to allow the app to mute app sounds when you are on a call. " & _
                "If you previously selected 'Don't ask again' then go to screen that has all " & _
                "of your apps. Locate this app and long press on the app icon. A screen  " & _
                "will pop up. Tap App info and scroll until you find Permissions and tap it." & _
                "You will find the Phone permission toggle. Tap it so it's 'On'", _
                "Please allow this permission")
            
            ImageViewExit_Click
        End If
    End If
 

rleiman

Well-Known Member
Licensed User
Watch the video tutorial and quickly remove the first Check call.

Runtime Permissions (Android 6.0+ Permissions)

Why aren't you using smart strings???

Click on the List Permissions and make sure that the permission is listed there (it is explained in the video tutorial).
Based on the the video tutorial I used the following lines of code to see if the permission dialog would be shown, but it was never displayed asking for user for the permission. Instead, execution did hit my Log statement indicating the permission was false as if the dialog was shown and "Deny" was chosen.

B4X:
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Layout")
   
    rp.CheckAndRequest(Starter.rp.PERMISSION_READ_PHONE_STATE)
    Wait For Activity_PermissionResult (permission As String, Result As Boolean)

    Log("The result is: " & Result)

There is no other code in this sub routine these lines of code so I know it's not being influenced by any code before or after it.

Is there a way to just call the Request dialog directly? It would be nice to let the user know that the permission will be asked for before they get to allow it.
 
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Click on Logs - List Permission and post a screenshot of the permissions dialog.
Screenshot 2020-11-03 at 05.42.41.png
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Uninstall the app before installing it again. This will forget all the app permissions and it should ask again.
I tried that but it made no change. I must be the coding which I'm not doing correctly because it never shows the dialog. What coding are you using to just call the dialog?
 
Upvote 0

rleiman

Well-Known Member
Licensed User
The answer is in post #5. You will never be granted a permission if it is not in this list.

I guess that you haven't added the code that actually needs the permission.
I viewed the video tutorial again and it's helpful, but didn't see any mention of the need to add a permission request. From the tutorial, I assumed it would call the dialog. I will search the forum to see if there's a reference on how to do that.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Why do you need this permission?
So I can turn off the sound from the ExoPlayer if the user gets or makes a phone call.

I just found on the forum that I need to add a line in the manifest so the permission will be in the list. I didn't do that because the tutorial stated doing that was for older versions of Android but I will try that and see if it works.
 
Upvote 0

Geezer

Active Member
Licensed User
The permission box won't be shown unless somewhere else in your code is something that actually would need the permission.

For example, if you add code that will trigger when the phone rings, the permission would be required and hence the permission box would be shown as intended
 
Upvote 0

rleiman

Well-Known Member
Licensed User
The permission box won't be shown unless somewhere else in your code is something that actually would need the permission.

For example, if you add code that will trigger when the phone rings, the permission would be required and hence the permission box would be shown as intended
Good catch. We didn't add the phone state checking code yet and we thought we would just test the part asking for permission first. Next time we will add that coding first before dealing with the permissions.

Here's what worked after finding the correct wording for the phone state permission from a list of permission I found in the forum.

B4X:
'AddPermission(android.permission.PERMISSION_READ_PHONE_STATE)
AddPermission(android.permission.READ_PHONE_STATE)

No errors were generated by what I was using in the manifest editor so I thought it was the correct one because. We used the text that was provided by the autofill when typing "rp.CheckAndRequest(Starter.rp." The autofill suggested PERMISSION_READ_PHONE_STATE and that's what I placed into the manifest editor. Ultimately READ_PHONE_STATE is what actually worked so I'm marking this thread as solved.

Thanks everyone for helping.
 
Upvote 0
Top