Search code examples
androidfilerootwhatsapp

How can i copy a file from a rooted directory to another directory in a non rooted android phone prorammatically?


Can i copy a file from a rooted directory like data/data/something/ to another directory in non rooted android phone prorammatically ? If yes then how ? If no then how whatsapp stores its key file in directory data/data/com.whatsapp.com in all the phones (non -rooted phones also)


Solution

  • Short answer: yes

    Long answer: Yes, but only from application's directory. The app have acces to own data directory (e.g. /data/data/app.package.name/) but have no access to toher directories in /data partition. You can store files in own directory without extra permissions or tools but you can not do it with other data directories without root

    You can get the path to that directory using context.getDataDir() but it is not available on api lower 24. You should use context.getFilesDir(), context.getCacheDir() or context.getDir(String, int) instead