Android Question Having trouble with runtime permissions

MichaelAust

Member
Licensed User
Longtime User
Hi, I have added the runtime permissions to a biggish project, according to the tutorial, but I am experiencing app crashes when the CheckAndRequest function is called.
I made an app based on the one which b4a creates when you start a new project, just adding the runtime permissions code, and it does the same as my app.
I presume I have done something wrong, I also put a log in the zip file.
Using B4A 10.2
I also removed Oracle Java and installed OpenJdk according to the install instructions, but this didn't help.
Hoping for some help,
Thanks,
Michael
 

Attachments

  • BloodSugar5.zip
    10.6 KB · Views: 250

Mahares

Expert
Licensed User
Longtime User
Hoping for some help,
I tested your tiny project with this code. After requesting permission. It worked. See attached project
B4X:
Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")   'even with this uncommented, it worked
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, PermResult As Boolean)
    If Not(PermResult) Then
        Log(Permission & " " & PermResult)
        Return
    End If
    File.WriteString(File.DirRootExternal,"Test.txt","Test") ' Made no difference.
End Sub
 

Attachments

  • Michaelaust.zip
    9.3 KB · Views: 295
Upvote 0

MichaelAust

Member
Licensed User
Longtime User
Thanks for both your replies, I believe the problem was the android.jar version. This page https://www.b4x.com/android/forum/threads/87610/#content said to Use the latest (android.jar) version available to avoid compilation errors. Mine hadn't been updated for a while, and when I reinstalled the Android SDK + Required Resources and set the path according to the installation instructions, it compiled and didn't crash, and even though the android.jar is the sdk 30 version and the target sdk is set to 29 it wrote a file in File.DirRootExternal
Thank You
Michael
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
even though the android.jar is the sdk 30 version and the target sdk is set to 29 it wrote a file in File.DirRootExternal
That is the way it is supposed to work:
1. Path to android.jar i is SDK 30
2. Target SDK in manifest: 29
No surprises there.
 
Upvote 0
Top