Android Question creating folder for saveing files SdkVersion="33"

aligol

Member
Hi I wrote to play music when I run app at emulator and download a music a folder create successfully with downloaded music but when I install app at real phone sumsung Galexy a7 android 10 I see no folder with any music file at download directory. I please an expert or someone who knows the problem to help me, thanks in advance
B4X:
Sub lbl_play_Click
    Dim r1,r2 As Boolean
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For activity_PermissionResult (permission As String, result As Boolean)
    r1=result
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For activity_PermissionResult (permission As String, result As Boolean)
    r2=result
    If File.Exists(File.DirRootExternal&"/Download","barplayer") = False Then
        File.MakeDir(File.DirRootExternal,"Download/barplayer")
    End If
    
    paath =File.DirRootExternal&"/Download/barplayer/"
    Dim typee As String = Main.typee
    If r1 = True And r2 = True Then
        
        If typee = "music" Then
            If File.Exists(paath,Main.namefordownload&".mp3") = True Then
                'play
                footer.SetVisibleAnimated(100,True)
                mp.Load(paath,Main.namefordownload&".mp3")
                mp.Play
                lbl_play.Visible=False
            'pause previous page music
                t.Enabled=True
                SeekBar1.Enabled=True
                lblplay.Text = Chr(0xE034)
                sc.Top = 56dip
                sc.Height = Activity.Height -256dip   
            Else
                Log("clicked")
                pnl_download.SetVisibleAnimated(100,True)
                'download
                
            End If
            
        Else
         If File.Exists(paath,Main.namefordownload&".mp4") = True Then
                 Dim inten As Intent
                 Dim pm As PackageManager
                inten=pm.GetApplicationIntent("com.mxtech.videoplayer.ad")
                  If inten.IsInitialized = True Then
                codebox.MXPlayer(File.Combine(paath,Main.namefordownload&".mp4"))
                
                   Else           
                        Dim Provider As FileProvider
                        Provider.Initialize
                        Dim FileName As String = Main.namefordownload & ".mp4"
                        File.Copy(paath, FileName, Provider.SharedFolder, FileName)
                        Dim vid As Intent
                        vid.Initialize(vid.ACTION_VIEW,"")
                        Provider.SetFileUriAsIntentData(vid, FileName)
                        vid.SetType("video/*")
                        StartActivity(vid)
                   End If
         Else
                pnl_download.SetVisibleAnimated(100,True)
                      
      End If   
        End If
    End If
End Sub
 
Solution
do we cannot make folder of course getting permission by file.makeDir on user phone any more?
True. You can't unless you are using File.DirInternal=XUI.DefaultFolder.
The read/write external storage permissions are no longer relevant.

Is the user have to chose the path for each download Every time?
You can use ExternalStorage to get a more persistent permission, but it is a bit more complicated.

aligol

Member
Whenever you see code with File.DirRootExternal you immediately know that it is wrong.

You cannot directly access those folders.

The various options are listed here: SaveAs - Let the user select a target folder + list of other related methods
Thanks for reply, pardon me for my dummy questions,I'm newbie
do we cannot make folder of course getting permission by file.makeDir on user phone any more?
Is the user have to chose the path for each download Every time?
If yes, Is there a way for a simple app to get user permission just once to use the download directory all the times?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
do we cannot make folder of course getting permission by file.makeDir on user phone any more?
True. You can't unless you are using File.DirInternal=XUI.DefaultFolder.
The read/write external storage permissions are no longer relevant.

Is the user have to chose the path for each download Every time?
You can use ExternalStorage to get a more persistent permission, but it is a bit more complicated.
 
Upvote 0
Solution
Top