1

In my application I have an existing SQLite database attached. On start it's copied to phone and then being used. I know how to check if this database is already copied, but I want to check if database on the phone is the same as stored in APK. Is there any way to compare them? I want to do that programmatically.

Original database is stored in assets folder.

4
  • try compare the file size in bytes ? Commented Apr 6, 2012 at 6:27
  • Yeah, that's a good idea. How can I get sizes of these files? Original is in assets folder in my APK, and copied is in /data/data/my.package/databases/. Commented Apr 6, 2012 at 6:57
  • for assert db: context.getAssets().open("assert_db").available(); and new File("/data/...").length(); for the actually db. Commented Apr 6, 2012 at 7:02
  • ye, the available sometimes has some problem, so you can read full content to memory, you can get the bytes size, or you can save the size with hardcode. maybe the hardcode is not a good idea, it depend on your requirement. Commented Apr 6, 2012 at 7:51

2 Answers 2

1

If you have a rooted Phone then you can Watch the Details of It. but if your phone is not rooted then you are won't be able to see it.

Another thing if you have copied the Application in your Phone then it will definitely work.

So Conclusion is that If you have a Rooted Phone then you will be able to See and Compare, if possible try to compare its size or Time on which it is Installed.

Sign up to request clarification or add additional context in comments.

Comments

1

If you have attach a DataBase with your APK and you successfully copied to your phone that exactly means that you have your old data base copied.So i think no need to compare.If you want to compare then compare all record in Table.

Second if you want to remember that your data base is already copied then use one flag in share preferences.Save true once copied.Then check its value

Updated

To listing all Table

select name from sqlite_master where type = 'table'

If both data base have same table then compare record of these corresponding Table

4 Comments

Original database contents are going to change, but it wouldn't replace the old one on phone because it is already there. That's why I'm trying to find a way to compare them.
It will not replace then you can compare Total Table if both have same number Table then compare records that's the way to do it
I'm not sure how to open database in my APK.
But your question state that you copied it. and just want to compare both data base.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.