Android Question B4A How do I copy a data file at installation of the app

Peter Meares

Member
Licensed User
Longtime User
I have started to play with programming an application for my phone. Works well under B4J on the PC.
Simple program to record books I have read so I have them when in the bookshop.
Currently the list is a CSV file on my PC, and I want to know how to load it onto the phone during installation of the app.
I have the TextEditor (@Erel) running on the emulator and will expand from there.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
open the IDE (B4A) and click on Files below the right panel and select you csv.
Then add to your code the following lines


B4X:
'Copies a database file that was added in the Files tab. The database must be copied to a writable location.
'This method copies the database to the storage card. If the storage card is not available the file is copied to the internal folder.
'The target folder is returned.
'If the database file already exists then no copying is done.
Sub CopyDBFromAssets (FileName As String) As String
    
    Try
    
        Dim TargetDir As String
    
        If File.ExternalWritable Then
            TargetDir = DBFileDir
        Else
            TargetDir = File.DirInternal
        End If
    
        If File.Exists(TargetDir, FileName) = False Then
            File.Copy(File.DirAssets, FileName, TargetDir, FileName)
        End If
    
        Return TargetDir
    
    Catch
        Log("CopyDBFromAssets " & LastException.Message)
        
        Return ""
    End Try
    
End Sub
 
Upvote 0
Top