Android Question [Solved]media store shown problem

Theera

Expert
Licensed User
Longtime User
I have tested the GeoT's code in this . The first time to run is okay and then run again ,it has error about runtime. How to repair the code.
 

Theera

Expert
Licensed User
Longtime User
I'm sorry that it showed Thai language as follows picture. It advise to update about runtime which I don't understand to manage.
 

Attachments

  • Screenshot_20240303_140751.png
    Screenshot_20240303_140751.png
    150.7 KB · Views: 160
Upvote 0

Theera

Expert
Licensed User
Longtime User
If the app crashes then there must be an error message in the logs.
The first time for run is Okay, but when I run it again, it has problem.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Please to see my clip, after install app.I can't explain in English.There is no error inthe logs file.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
You can try to add this line in the Manifest editor.
Add to the Manifest:
AddPermission(android.permission.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
The app will not be published in Google Play, right?
After I have done,it has error while compiling code "Object reference not set to an instance of an object."
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I think maybe there is another of Runtimepermission library in your additional libraries folder, find and delete it
 
Last edited:
Upvote 0

Theera

Expert
Licensed User
Longtime User
Plese see this code ,I think it has be initialized already.
B4X:
' '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

I've tried to delete these codes and addpermission directly in the manifest file,but the result still has error.
 
Last edited:
Upvote 0

Theera

Expert
Licensed User
Longtime User
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:
B4X:
Public folder As String
Public rp As RuntimePermissions
folder = rp.GetSafeDirDefaultExternal("")
You can try it like that.
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.
 

Attachments

  • MediaStoreShown_3.zip
    15 KB · Views: 147
Upvote 0

teddybear

Well-Known Member
Licensed User
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
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
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
Your code can be solved.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Thank you for the kind of both of you.
 
Upvote 0
Top