how to access path of database or file of different app in android

前端 未结 1 1249
北海茫月
北海茫月 2021-01-23 02:49

Is it possible to get path of database file in android at path : \"/data/system/accounts.db\"

in my app i want to use this database, but not getting its path. if i do ha

相关标签:
1条回答
  • 2021-01-23 03:26

    You can use android.os.Environment.getDataDirectory() to get the path to the data directory. Don't use the mContext.getDatabasePath if the db is not in the data dir of your app.

    Also see Is it possible to move the internal DB to the SDCard?

    if you want to search, do a recursive file search via something like this:

    private void searchFile(String startingPoint) {
    
        Files[] files = File("/data").listFiles(); 
        for (File f:files) {
            if (f.isDirector) searchFile(f);
            else if (f.getName().equals("accounts.db")) {
                // delete db here...
                // and exit the search here...
            }
        } 
    }
    

    and check if it contains the accounds.db. If you reach another subdirectory, call your own function recursively with the subfolder as the starting point, and so on....

    But make sure you have read access to the relevant folder you set as starting point to start the search.

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