Android Question Problems with the permissions

Discussion in 'Android Questions' started by francesco paolo lavecchia, Jun 29, 2019.

  1. francesco paolo lavecchia

    francesco paolo lavecchia Member Licensed User

    Hi all,
    I don't know why rp.CheckAndRequest(Permission) works for

    Permissions.Add(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Permissions.Add(rp.PERMISSION_ACCESS_FINE_LOCATION)

    and doesn't work for

    Permissions.Add(rp.PERMISSION_READ_PHONE_STATE)
    Permissions.Add(rp.PERMISSION_CALL_PHONE)

    I mean this,

    upload_2019-6-29_17-25-17.png








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

    Dim rp As RuntimePermissions
    Dim numPermission As Int
    Dim noPermission As Int
    Dim Permissions As List

    End Sub

    Sub Activity_Create(FirstTime As Boolean)

    Dim i As Int
       
    'Do not forget to load the layout file created with the visual designer. For example:
       'Activity.LoadLayout("Layout1")

       Permissions.Initialize
       Permissions.Add(rp.PERMISSION_READ_PHONE_STATE)
       Permissions.Add(rp.PERMISSION_CALL_PHONE)
       Permissions.Add(rp.PERMISSION_READ_EXTERNAL_STORAGE)
       Permissions.Add(rp.PERMISSION_ACCESS_FINE_LOCATION)

       numPermission = 
    0
       noPermission = 
    0
       
    Do While (numPermission < (Permissions.Size-1))
           
    For i=0 To Permissions.Size-1
               
    Dim Permission As String = Permissions.Get(i)
               
    If Not(rp.Check(Permission)) Then
                   rp.CheckAndRequest(Permission)
                   
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
                   
    If Result Then
                       numPermission = numPermission + 
    1
                       noPermission = noPermission - 
    1
                   
    Else
                       noPermission = noPermission + 
    1
                       
    Msgbox("No Permission: " & Permission,Application.LabelName)
                       
    If noPermission = (Permissions.Size) Then
                           
    ExitApplication
                       
    End If
                   
    End If
               
    End If
           
    Next
       
    Loop

       
    Msgbox("Ok",Application.LabelName)

    End Sub
    Thanks in advance
     
  2. francesco paolo lavecchia

    francesco paolo lavecchia Member Licensed User

    Code:
    'This code will be applied to the manifest file during compilation.
    'You do not need to modify it in most cases.
    'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "5" android:targetSdkVersion="26"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    CreateResourceFromFile(Macro, Themes.DarkTheme)
    'End of default text.

    AddPermission(android.PERMISSION_READ_PHONE_STATE)
    AddPermission(android.Permissions_CALL_PHONE)
    AddPermission(android.permission.READ_EXTERNAL_STORAGE)
    AddPermission(android.permission.ACCESS_FINE_LOCATION)
     
  3. DonManfred

    DonManfred Expert Licensed User

  4. francesco paolo lavecchia

    francesco paolo lavecchia Member Licensed User

    I tried it before doing my code as I posted it but it didn't work. I tried many several options...
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please upload a small project that demonstrates the issue.
     
  6. francesco paolo lavecchia

    francesco paolo lavecchia Member Licensed User

    I also made a little video...

    You have to change
    PERMISSION1 in permission.z01
    PERMISSION2 in permission.z02
    PERMISSION3 in permission.z03

    (extensions z01,z02,z03 are not allowed)
     
    Last edited by a moderator: Jun 30, 2019
  7. Erel

    Erel Administrator Staff Member Licensed User

    Please use File - Export as zip and upload a single zip file with the project.
     
  8. francesco paolo lavecchia

    francesco paolo lavecchia Member Licensed User

    How can i upload the video? it's too big...
     

    Attached Files:

  9. Erel

    Erel Administrator Staff Member Licensed User

    1. Code with Msgbox is not considered valid code. You should never use modal dialogs. Use MsgboxAsync instead.
    2. This code is much simpler: https://www.b4x.com/android/forum/threads/handle-multiple-permission-request.94611/#post-598788
    3. First step is to click on the List Permissions button (Logs tab):

    [​IMG]

    You can immediately see that there are only two "dangerous" permissions.
    The other two that should be marked with an asterisk are not marked because the permission case is incorrect.
     
  10. francesco paolo lavecchia

    francesco paolo lavecchia Member Licensed User

    Sorry but I don't understand
    You are saying not to use msgbox, ok, but the the problem is different:

    the code doesn't stop on:

    rp.CheckAndRequest(READ_PHONE_STATE)
    rp.CheckAndRequest(CALL_PHONE)

    so the user can't answer to any request

    This thing doesn't happen for

    rp.CheckAndRequest(READ_EXTERNAL_STORAGE)
    rp.CheckAndRequest(ACCESS_FINE_LOCATION)

    I tried any options but the problem is always the same.

    What do you mean with: First step is to click on the List Permissions button?

    upload_2019-7-1_8-58-40.png
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    I've tested the project you've uploaded. As you can see in the screenshot I posted the permissions were not added to the manifest editor correctly.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice