Android ADB access to application databases without root

后端 未结 5 769
难免孤独
难免孤独 2020-12-02 05:20

Can anyone tell me, is it possible to use the ADB to pull and push a database from an app, without root privileges on the phone?

For example, I know the location on

5条回答
  •  时光取名叫无心
    2020-12-02 05:36

    We set the file permissions to readable for all users from within the app.

    if (BuildConfig.DEBUG)
    {
        new File(mDB.getPath()).setReadable(true, false);
    }
    

    Then just pull the .db off with adb normally.

    adb -d pull //data/data/xxxxx/databases/xxxxx.db .
    

    NOTE: I've discovered that this needs to be done each time the database file is opened, for example in onCreate as well as the constructor of your SQLiteOpenHelper wrapper (when your database is not null) or perhaps onOpen. If only in onCreate, then the next time you run your app and the .db already exists, for some reason the permissions have been changed back. This might have something to do with how Android manages its data.

提交回复
热议问题