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

前端 未结 4 1218
别跟我提以往
别跟我提以往 2020-12-10 03:50

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/

相关标签:
4条回答
  • 2020-12-10 04:30

    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.

    0 讨论(0)
  • 2020-12-10 04:34

    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.

    0 讨论(0)
  • 2020-12-10 04:41

    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

    0 讨论(0)
  • 2020-12-10 04:45

    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.

    0 讨论(0)
提交回复
热议问题