Android Question RuntimePermissions throws error in release mode only

MrKim

Well-Known Member
Licensed User
Longtime User
The following code:
B4X:
Sub Process_Globals
    Dim RTP As RuntimePermissions
End Sub


Sub TestNetBtn_LongClick
    RTP.CheckAndRequest(RTP.PERMISSION_READ_EXTERNAL_STORAGE)
    NetDir.Visible = True
    NetDir.Text =    File.DirRootExternal & "/Skdata"
    UserName.Text = "Demo"
    Password.Text = "1X2X3XDemo"
End Sub

Throws this error:
B4X:
java.lang.Exception: Sub activity_permissionresult was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:192)
    at anywheresoftware.b4a.BA$2.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
java.lang.Exception: Sub activity_permissionresult was not found.

In release mode. There is no error in debug mode. Note that I had already given permission (when in debug mode)

I uninstalled and reinstalled the release app then the error changed a little bit.
IT DOES prompt for permission, when I click allow the following is what I get:
B4X:
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
ipisetup$ResumeMessagerun (java line: 300)
java.lang.Exception: Sub activity_permissionresult was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:192)
    at anywheresoftware.b4a.BA$2.run(BA.java:360)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:432)
    at com.ISS.MobileJobLogging.ipisetup$ResumeMessage.run(ipisetup.java:300)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
java.lang.Exception: Sub activity_permissionresult was not found.

At first I thought it was not letting me access external data but it turns out that I have to close and reopen the app. THEN I can access the data.

So things seem to work OK but it would be nice not to throw an error.

Recently purchased android Insignia (Best Buy Brand) tablet. Android 7.0
B4A Version 7.30
 

MrKim

Well-Known Member
Licensed User
Longtime User
Sigh, never mind. Solved it myself.
Needed
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)


End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, it is simpler to use Wait For:
B4X:
Sub TestNetBtn_LongClick
    RTP.CheckAndRequest(RTP.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = True Then
    NetDir.Visible = True
    NetDir.Text =    File.DirRootExternal & "/Skdata"
    UserName.Text = "Demo"
    Password.Text = "1X2X3XDemo"
   End If 
End Sub
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
BTW, it is simpler to use Wait For:
B4X:
Sub TestNetBtn_LongClick
    RTP.CheckAndRequest(RTP.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = True Then
    NetDir.Visible = True
    NetDir.Text =    File.DirRootExternal & "/Skdata"
    UserName.Text = "Demo"
    Password.Text = "1X2X3XDemo"
   End If
End Sub
I'm still getting the hang of Wait For. Seems like some commands it seems like it should work and doesn't. And then getting the syntax right for the given command.
It would be really nice to have a list of examples for all possibilities.
Command()
Wait For
Command2()
Wait For...
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I'm still getting the hang of Wait For. Seems like some commands it seems like it should work and doesn't. And then getting the syntax right for the given command.
It would be really nice to have a list of examples for all possibilities.
Command()
Wait For
Command2()
Wait For...

It's very easy to use it in a wait for construct. Can you show us your code which isn't working?
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
It's very easy to use it in a wait for construct. Can you show us your code which isn't working?
I'm sure Erel's example would work fine. I was speaking in general about wait for. Probably shouldn't have done that here. This is a quick and dirty temporary hack so there is no need to clean up the code, there is nothing in Activity_PermissionResult anyway.
 
Upvote 0
Top