Android Question Can not copy database from File.Assents folder

Gabriel Herrmann

Member
Licensed User
Hello together,

I have a problem - I cannot copy my database (SQLite) from File.Assents folder to public folder.
Normally if run the app on my device - the database exsits and everything works fine.

Now I would like to move the database to an public folder because since Android 11 I don't have access to app folder via FTP connection.

B4X:
    NewDBFolder = File.DirRootExternal & "/TestFolder/"
    
    If File.Exists(NewDBFolder, "") = False Then
        File.MakeDir(NewDBFolder, "")
    End If

    If File.Exists(NewDBFolder, "MyDatabase.db") = False Then
        If File.Exists(File.DirAssets, "MyDatabase.db") Then
            Wait For (File.CopyAsync(File.DirAssets, "MyDatabase.db", NewDBFolder, "MyDatabase.db")) Complete (Success As Boolean)
            bStartCopy = True
        Else if File.Exists(SourceFolder, "MyDatabase.db") Then
            Wait For (File.CopyAsync(SourceFolder, "MyDatabase.db", NewDBFolder, "MyDatabase.db")) Complete (Success As Boolean)
            bStartCopy = True
        Else if File.Exists(File.DirInternal, "MyDatabase.db") Then
            Wait For (File.CopyAsync(File.DirInternal, "MyDatabase.db", NewDBFolder, "MyDatabase.db")) Complete (Success As Boolean)
            bStartCopy = True
        Else
            Msgbox2Async("Cannot find database", "Fehler - Folder error", "OK", "", "", info, False)
            Wait For Msgbox_Result (iResult As Int)
            If iResult = DialogResponse.POSITIVE Then
                bStartCopy = False
            End If
        End If
    End If

Many thanks and best regards
Gabriel
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Do not use File.dirRootExternal.

There are many threads about this and also how to share files.

see



 
Upvote 0

Gabriel Herrmann

Member
Licensed User
Ok, thanks Andrew.
I will read the links - but at the moment it's not the problem with File.DirRootExternal...

The problem is, I can't find my exciting database... my code always runs into the ELSE block.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Have you fixed this problem yet? If not then I have several questions ...

1. As Andrew says, you should avoid File.DirRootExternal with current Android versions. How have you changed this code?

2. As Agraham says, File.Exists should not be used with File.DirAssets. How have you modified this code?

3. In any case, using File.Exists in a conditional statement with File.DirAssets would be illogical - the file would either always be present or never be present, so only one leg of the conditional will ever be exercised.

By the way, if the file is not in File.DirAssets how will it have got to the other folders that you are trying to check?

4. Why are you using File.CopyAsync rather than File.Copy? Is the file really huge?

5. Following from question 4, what other useful work is taking place during the copy process? How can we be sure that that is not where a problem lies?

6.
... since Android 11 I don't have access to app folder via FTP connection.

Unless there is a second meaning for FTP that I know nothing about, FTP is still fully functional in all Android versions. But in any case, what is the connection with this problem?


I have several apps where I put a "get-you-started" version of a data library in File.DirAssets to install on the first run, but immediately replace it (if internet is available) with a larger and up-to-date dataset using FTP. This works very well, and I wonder if that is what you are trying to do here.

It looks as though your code example is from a test application. If that is the case can you upload the project? My feeling is that, although the code you show has some problems, there might be another problem elsewhere.
 
Upvote 0

Gabriel Herrmann

Member
Licensed User
Hello,
sorry for my delay response - but at the moment I don't found a solution.

@Brian:
With my posted code I just wanted to say/show that I cannot find my database - which is available in File.DirAssets. It's the same as Agraham says.

My problem is that I want to copy exactly the file from the File.DirAssets to another folder - the reason is that the database should be copied to another folder after installation.

So I would like find a solution for this!

If I found a solution I will posted it here.
 
Upvote 0
Top