Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current sqlite database size or package size in Android?

Tags:

android

sqlite

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-developers/browse_thread/thread/df94daae34336aad/f96a8425549c6637 (is this still the current situation?)

Getting installed app size (unsopported hack - do not use it)

So is there any way to get the current sqlite database size? I've found a getMaxSize method or getPageSize but I'm not able to find the total number of pages.

like image 606
Bedo Avatar asked Jun 15 '11 21:06

Bedo


People also ask

How do I find the size of a SQLite database?

To get the amount of used space you can do SELECT (page_count - freelist_count) * page_size as size FROM pragma_page_count(), pragma_freelist_count(), pragma_page_size(); (Running VACUUM would recover the unused space and reduce the file size).

What is the size of SQLite database in Android?

Maximum Database Size 140 tb but it will depends on your device disk size.

What is the size of SQLite?

The maximum size of a database file is 4294967294 pages. At the maximum page size of 65536 bytes, this translates into a maximum database size of approximately 1.4e+14 bytes (281 terabytes, or 256 tebibytes, or 281474 gigabytes or 256,000 gibibytes).


1 Answers

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

File f = context.getDatabasePath(dbName);
long dbSize = f.length();

Cheers

like image 120
DroidBot Avatar answered Sep 29 '22 21:09

DroidBot