Skip to content Skip to sidebar Skip to footer

How To Get The Current Sqlite Database Size Or Package Size In Android?

I can't get the total amount of data used by an Android Application (or package), because the official API support has been deleted: http://groups.google.com/group/android-develope

Solution 1:

Perhaps someone could verify if this is an acceptable approach, but for a while I was using this:

Filef= context.getDatabasePath(dbName);
longdbSize= f.length();

Cheers

Solution 2:

You can query the database with these two:

pragma page_size;
pragma page_count;

(see the sqlite pragma docs).

Multiply the first by the second and you'll get total pages used.

Solution 3:

You can use this raw query as well, on sqlite 3.16.0+:

SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size();

It returns the "size" column with the single row.

Solution 4:

Just to add-on about the size.

When I used the code by DroidBot, it works. But the size may not straightaway increase when data is entered into the database (especially if the data is very small). Database will only increment in 1024 bytes (e.g from 8192 bytes to 9216 bytes).

So, to see the database size increase straightaway, try putting in a large amount of data.

Post a Comment for "How To Get The Current Sqlite Database Size Or Package Size In Android?"