The first time for run is Okay, but when I run it again, it has problem.If the app crashes then there must be an error message in the logs.
AddPermission(android.permission.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
After I have done,it has error while compiling code "Object reference not set to an instance of an object."You can try to add this line in the Manifest editor.
The app will not be published in Google Play, right?Add to the Manifest:AddPermission(android.permission.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
' 'agraham's code. Determine if the app already has MANAGE_EXTERNAL_STORAGE call Environment.isExternalStorageManager()
' Return True if this app already has MANAGE_EXTERNAL_STORAGE permission
Public Sub HasPermission As Boolean
Dim has As Boolean
Dim jo As JavaObject
jo.InitializeStatic("android.os.Environment")
has = jo.RunMethod("isExternalStorageManager", Null)
Return has
End Sub
Sub CheckAndRequestPermission
' Choose which permission to request in order to access external storgage
If SdkVersion < 30 Then
Log("SDK = " & SdkVersion & " : Requesting WRITE_EXTERNAL_STORAGE permission")
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$)
Else
'It doesn't work on my Android 11
' rp.CheckAndRequest("android.permission.READ_MEDIA_IMAGES") 'rp = RuntimePermissions lib
' Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
' If Result = True Then
' End If
' Log($"PERMISSION_READ_MEDIA_IMAGES = ${rp.Check("android.permission.READ_MEDIA_IMAGES")}"$)
Log("SDK = " & SdkVersion & " : Requesting MANAGE_EXTERNAL_STORAGE permission")
Log("On Entry MANAGE_EXTERNAL_STORAGE = " & HasPermission)
If Not(HasPermission) Then
MsgboxAsync("This app requires access to all files, please enable the option", "Manage All Files")
Wait For Msgbox_Result(Res As Int)
Log("Getting permission")
Log(HasPermission)
Dim inte As Intent
inte.Initialize("android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", "package:" & Application.PackageName)
StartActivity(inte)
End If
End If
btnImageFolders.Enabled = True
btnVideoFolders.Enabled = True
End Sub
Public folder As String
Public rp As RuntimePermissions
folder = rp.GetSafeDirDefaultExternal("")
It's GeoT's code. I have downloaded for study. I don't understand his code what has error. I know that it's useful in coding in the future.In my new version of the Calendar notes app: A calendar made easy i don't use @agraham 's class.
I use a folder this way:
You can try it like that.B4X:Public folder As String Public rp As RuntimePermissions folder = rp.GetSafeDirDefaultExternal("")
Sub CheckAndRequestPermission
' Choose which permission to request in order to access external storgage
If SdkVersion < 30 Then
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$)
Else
rp.CheckAndRequest("android.permission.READ_EXTERNAL_STORAGE") 'rp = RuntimePermissions lib
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
End If
btnImageFolders.Enabled = True
btnVideoFolders.Enabled = True
End Sub
Your code can be solved.I guess your Android OS is 12-, try this code
B4X:Sub CheckAndRequestPermission ' Choose which permission to request in order to access external storgage If SdkVersion < 30 Then rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted Wait For Activity_PermissionResult (permission As String, Result As Boolean) Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$) Else rp.CheckAndRequest("android.permission.READ_EXTERNAL_STORAGE") 'rp = RuntimePermissions lib Wait For Activity_PermissionResult (permission As String, Result As Boolean) End If btnImageFolders.Enabled = True btnVideoFolders.Enabled = True End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?