I have implemented the backup and restore feature of DB in-app. Users can choose any .db file from file picker intent. But the drawback of the system is the user can import any .db file that may be .db file of another app and as a result, my app will crash as tables will be not found.
Asked
Active
Viewed 118 times
2 Answers
2
You could try opening the database. If it fails to load you could catch that exception.

garritfra
- 546
- 4
- 21
-
But what about if tables in db file does not match original db. – Dhia Shalabi Mar 22 '21 at 07:34
2
You may consider taking md5 checksum
for the database file when they decide to backup it; and save the list of valid md5 check sums in a private database.
When they decide to restore one, then get the md5 of it and confirm it's in your list.
Here you can find how you can do md5 checksum for a file.

Zain
- 37,492
- 7
- 60
- 84
-
thanks for the answer..is there any drawback of the method suggested by garritfra below..as I think that would be very easy and quick to implement – sum20156 Dec 11 '20 at 13:50
-
1the method of @garritfra is simple and easy, I didn't try it myself, but I can remeber that for a project of mine, I had a database file that I download from the internet, and read it locally; but when the user disconnects the internet before the file completes, and then they open it in database; there was no exception is raised, but no data comes up as well >>> may be the database scheme is correct .. but the data itself (data rows) maybe not complete >> I prefer to go first with garritfra method .. but test it well to make sure that an exception is raised for every case – Zain Dec 11 '20 at 13:56