Android Question how to find app's folder (android 7+) ?

peacemaker

Expert
Licensed User
Longtime User
Hi, All

There is a task to get files from another app in rooted Android 7. Reading file is tested, it's OK, if the path is known.
But if i have app's package name and the target file name - how to find the file in folders of the app ?
I mean, to find the exact full file path.
 

teddybear

Well-Known Member
Licensed User
Try the path File.DirInternal /data/user/0/packagename/files
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Question is not to try some, but to make an algorithm to find the path correctly, on any rooted device with various drive configurations.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Question is not to try some, but to make an algorithm to find the path correctly, on any rooted device with various drive configurations.
I mean that you can get your app fullpath using File.DirInternal and then replace the packagename substring of the fullpath with the packagename which you want to get file.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Hmm, indeed:
1) my app in MEMU emulator File.DirInternal gives his own path as "/data/user/0/MYPACKAGE/files"
2) but a file explorer gives the target app as "/storage/emulated/0/Android/data/TARGETPACKAGE/files"

And no folder of my app like "/storage/emulated/0/Android/data/MYPACKAGE/files"
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
And no folder of my app like "/storage/emulated/0/Android/data/MYPACKAGE/files"

This path ("/storage/emulated/0/Android/data/MYPACKAGE/files") is got by
B4X:
Starter.rp.GetSafeDirDefaultExternal("")
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hmm, indeed:
1) my app in MEMU emulator File.DirInternal gives his own path as "/data/user/0/MYPACKAGE/files"
2) but a file explorer gives the target app as "/storage/emulated/0/Android/data/TARGETPACKAGE/files"

And no folder of my app like "/storage/emulated/0/Android/data/MYPACKAGE/files"
/storage/emulated/0/Android/data/MYPACKAGE/files is File.DIrDefaultExternal, if your phone has TF card
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
So, this works:
B4X:
        Dim p As String = Starter.rp.GetSafeDirDefaultExternal("").Replace(Application.PackageName, TARGETPACKAGE) 
        Dim f As List = File.ListFiles(p)

It means that 2 paths can be checked, internal and external.
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
This path ("/storage/emulated/0/Android/data/MYPACKAGE/files") is got by
B4X:
Starter.rp.GetSafeDirDefaultExternal("")
If you are not sure which dir the file is in, you can test if it is existed both of internal and external dir
 
Upvote 0
Top