save file audio to sd card for all device

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello everyone, I created a program that does ascoltari mp3 files on telfono, I would like to share these files with WhatsApp, I managed to download the file to the sd memory card, but I noticed that not all phones have the same directory on samsung and the directory: external sd, while on the directory and lg: _externalsd
There is a method that allows you to save the audio file on sd memory card of any mobile?
 

margret

Well-Known Member
Licensed User
Longtime User
If you use code like below to create the location, you should be fine. The File.DirRootExternal will take care of the different location on different devices. Then create a directory with your app name/data and place your file in the data directory. This way any device that makes a call to File.DirRootExternal/yourapp/data/yourfiles will end up in the same directory.

B4X:
Sub Save_DataLocation
   If File.ExternalWritable Then
      File.MakeDir(File.DirRootExternal, "yourappname/data/yourfiles")
      'Your other code here, if needed
   End If
End Sub
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
thanks now I feel Margret, another question .... If the phone does not have the external memory card so that I do not crash, you could do to redirect the file to your phone and does not give error, I think we need an if statement, but as a set?
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
B4X:
'Option 1
Sub Save_DataLocation
   If File.ExternalWritable Then
      File.MakeDir(File.DirRootExternal, "yourappname/data/yourfiles")
      'Your other code here, if needed
   Else
      File.MakeDir(File.DirInternal, "mydata/yourfiles")
      'This creates a internal folder named /mydata under File.DirInternal
      'You will need to copy your required files to this folder or access them from 
      'File.DirAssets
   End If
End Sub


'Option 2
Sub Save_DataLocation
   If File.ExternalWritable Then
      File.MakeDir(File.DirRootExternal, "yourappname/data/yourfiles")
      'Set a Process_Global for Path
      Work_Path = File.DirRootExternal & "/yourappname/data"
   Else
      Msgbox("You SDCard is Missing or not Writable.  Access reset to Internal Memory", "NOTICE")
      'Set a Process_Global for Path
      Work_Path = File.DirAssets
   End If
End Sub
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
I continue to save on phone memory but it saves me about the memory card, I'd like that would save in the phone's external memory external_sd, the problem is that not all phones use the same directory, such as lg or so in some htc phones manages to save the external memory in others gives me error because the path is different
B4X:
Sub Save_DataLocation
    
      File.Copy(File.DirAssets, txt1.text & ".mp3" ,File.DirRootExternal,"external_sd/Audiocomics/data/Audio/"& txt1.text & ".mp3" )
      Msgbox("File salvato memoria esterna: Audiocomics/data/Audio/"& txt1.text & ".mp3","SALVATAGGIO ESEGUITO")
    Else
        File.MakeDir(File.DirInternal, "mydata/Audiocomics")
        File.Copy(File.DirAssets, txt1.text & ".mp3" ,File.DirInternal,"mydata/Audiocomics/"& txt1.text & ".mp3" )
      Msgbox("FILE SALVATO SULLA CARTELLA: mydata/Audiocomics/  " &" " & txt1.Text & ".mp3","SALVATAGGIO ESEGUITO")
    End If
   
   
End Sub
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Save_DataLocation
   Dim mFrom, mTo As String
   If File.IsDirectory(File.DirRootExternal & "/external_sd") Then
      File.MakeDir(File.DirRootExternal, "external_sd/Audiocomics/data/Audio)
      mTo = File.DirRootExternal & "/external_sd/Audiocomics/data/Audio/" & txt1.Text & ".mp3"
      mFrom = File.DirAssets & "/" & txt1.Text & ".mp3"
      File.Copy("", mFrom, "", mTo)
      Msgbox("File salvato memoria esterna: " & mTo, "SALVATAGGIO ESEGUITO")
   Else
      File.MakeDir(File.DirInternal, "mydata/Audiocomics")
      mTo = File.DirInternal & "/mydata/Audiocomics" & txt1.Text & ".mp3"
      mFrom = File.DirAssets & "/" & txt1.Text & ".mp3"
      File.Copy("", mFrom, "", mTo)
      Msgbox("FILE SALVATO SULLA CARTELLA: " & mTo, "SALVATAGGIO ESEGUITO") 
   End If
End Sub
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
thanks margret wonderful ;)
 
Upvote 0

BaGRoS

Active Member
Licensed User
Longtime User
If an external card is available, how can we ALWAYS get the right to write?
 
Upvote 0
Top