Android Question [SOLVED] Problem with permissions

CArlos13511

Member
Licensed User
Longtime User
Good
Sorry for the translation. Translation x Google
Testing the permission class in which annex the list I have the following error in logs. Could you help me solve it.
Thank you
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example Permission
    #VersionCode: 1
    #VersionName:
    '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 shared As String
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)
    shared=rp.GetSafeDirDefaultExternal("")
    Dim testFolder As String=rp.GetSafeDirDefaultExternal("test")
    File.WriteString(testFolder,"test.txt", "aaa")
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        Dim pid As PhoneId
        Log(pid.GetDeviceId)
    Else 
        Log("No Permission")
    End If
  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)


End Sub







Yesterday at 11:30 AM

Good
Sorry for the translation. Translation x Google
Testing the permission class in which annex the list I have the following error in logs. Could you help me solve it.
Thank you



B4X:




#Region Project Attributes
#ApplicationLabel: B4A Example Permission
#VersionCode: 1
#VersionName:
'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 shared As String
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)
shared=rp.GetSafeDirDefaultExternal("")
Dim testFolder As String=rp.GetSafeDirDefaultExternal("test")
File.WriteString(testFolder,"test.txt", "aaa")
rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Dim pid As PhoneId
Log(pid.GetDeviceId)
Else
Log("No Permission")
End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)


End Sub



Registo conectado a: motorola moto g(7) play
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/StringI in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in base.apk)
at anywheresoftware.b4a.objects.RuntimePermissions.Check(RuntimePermissions.java:55)
at anywheresoftware.b4a.objects.RuntimePermissions.CheckAndRequest(RuntimePermissions.java:79)
at CAB.Permissions.main$ResumableSub_Activity_Create.resume(main.java:418)
at CAB.Permissions.main._activity_create(main.java:381)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at CAB.Permissions.main.afterFirstLayout(main.java:104)
at CAB.Permissions.main.access$000(main.java:17)
at CAB.Permissions.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
** Activity (main) Resume **
 

drgottjr

Expert
Licensed User
Longtime User
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)

where is Activity_PermissionResult() sub?
 
Upvote 0

CArlos13511

Member
Licensed User
Longtime User
where is Activity_PermissionResult() sub?
Thanks for replying drgottjr:
I am following the Erel tutorial and cannot find the Sub Activity_PermissionResult (Permission As String, Result As Boolean). I have tried to see it several times and will not give it away.
Line 31 contains the Wait For call
Find an sub Activity_PermissionResult (Permission As String, Result As Boolean) and paste it but nothing?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tested your project as shown below. I also exported the full project. It worked for me. Make sure when you are asked for permission, you need to allow it.
B4X:
Sub Globals
    Private rp As RuntimePermissions
End Sub

Sub Activity_Create(FirstTime As Boolean)
'    shared=rp.GetSafeDirDefaultExternal("")
    Dim testFolder As String=rp.GetSafeDirDefaultExternal("test")
    File.WriteString(testFolder,"test.txt", "aaa")
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE) 
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        Dim pid As PhoneId
        Log("device id: " & pid.GetDeviceId)
    Else
        Log("No Permission")
    End If
End Sub
 

Attachments

  • rp040920.zip
    8 KB · Views: 197
Upvote 0

CArlos13511

Member
Licensed User
Longtime User
Mahares:
Thanks for your interest, but downloading the zip rp040920 (copy of the code sent) I still have the same message in the Logs and the device does not request permission and aborts its execution.

Registo conectado a: LENOVO Lenovo TB-7104F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/StringI in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/b4a.example--SNchNr8l8O1N-9yL9BJZg==/base.apk)
at anywheresoftware.b4a.objects.RuntimePermissions.Check(RuntimePermissions.java:55)
at anywheresoftware.b4a.objects.RuntimePermissions.CheckAndRequest(RuntimePermissions.java:79)
at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:414)
at b4a.example.main._activity_create(main.java:380)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6548)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
** Activity (main) Resume **
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Welcome to the wonderful world of Google's permissions. There is nothing wrong with the software of item 5. It also works without problems for me. But what strikes me is the phrase "does not request permission". ? This means that RunTimePermission uses a previously given permission or refusal. ? In view of the error message, a refusal is obvious. I suspect that RunTimePermission is based on a previously given refusal (can also have happened with another B4A Example software). What you can do is the following blunt ax method where you erase all given choices without uninstalling B4A-Bridge:

  1. Uninstall B4A Example on the tablet. Please note that different versions of B4A Example may be installed! Remove them all!
  2. Select B4A-Bridge and find the setting "Storage". For example, 10.80 MB is used in internal storage. Select "Erase data" (do not uninstall).
  3. Start b4A Bridge. Choose Enable FTP.
  4. Allow B4A-Bridge to access media and files.
  5. Go to Tools and connect to B4A-Bridge on the tablet.
  6. Choose under cleaning tools (Ctrl-p)
  7. Start the extracted program from item 5
If all goes well, the RunCheckPermission will now be requested and the text file should now be created.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…