How do I dynamically get the root path of the directory where my app is installed?
In the Internal Storage, the app package is stored, which can only be accessed with a rooted device.
What does “dynamically” mean?
I need to access a File.pdf with Start Activity. On my android 8.1 device I used the URI. file: ///sdcard/Makeroid/library/File.pdf. But on my other android 4.4 device it only worked with the URI. file: ///storage/Makeroid/library/File.pdf.
according to the device the uri will be started with sdcard or storage how can i identify this automatically?
you could use
- a relative path, which is
- a full generic path, which is
EDIT: are you trying to read a file form the assets of the app? this will not work like this…
file:///mnt/sdcard/ is the root directory of the External Storage
file:///sdcard/Makeroid/library/ is the same as:
These dirs are visible / accessible on your device, where (from an Android point of view) this “External Storage” is called “Internal Storage” (see below):
Internal Storage > Makeroid > library
The path to files in the assets is for the compiled app (APK):
file:///android_asset/ and for Companion:
From an Android point of view there are an Internal Storage and an External Storage.
1. Internal Storage
In the Internal Storage, the app package is saved:
which can only be accessed with a rooted device.
2. External Storage
The root directory of the External Storage is:
2.1. App-specific directory
In addition, there may be an app-specific directory (which can be created with Taifun’s File extension: App Inventor Extensions: File | Pura Vida Apps or the FileTools extension)
which is saved in the External (private) Storage, but does not require READ_ / WRITE_EXTERNAL_STORAGE permissions.
This app-specific (private) folder can only be accessed by your app.
2.2. Removable (micro) SD card
There may also be another External Storage: a removable (micro) SD card, eg:
that can only be read (on modern Android systems).
The root directory of the External Storage
is displayed on the device as Internal Storage (unfortunately this is a bit ambiguous).
Great! I’ve learned a lot about this.
But I wonder if there is a way to find out if the APK has been installed on internal or external storage. Is there this possibility?
As I said: /data/data/
<packageName>/ (see above: 1. Internal Storage)
See here for an excellent overview on this topic: https://www.dev2qa.com/android-read-write-external-storage-file-example/
"Internal storage is used to store android app private data such as files, cached files, shared_preferences and database files.
All those files is stored in android device folder /data/data/
<app packageName>/ . And only the android app can operate those files. In general internal storage files is saved in android device build-in flash disk memory."
It worked! It ran on two devices (the apk installed one on internal sdcard and one on external storage) using only the path: file: /// storage / emulated / 0 / Android / data / packname / files.
Thanks for listening! \The/
Copying from the assets does not work for APK (checked with AI2):
Two slashes from
file:///android_asset/ are removed, result:
Runtime Error: file:/android_asset/test.1.pdf (No such file or directory)
usually (and this is how the file component is implemented) to access the assets you have to use two slashes //, see also the documentation Storage
Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes).
in case this extension uses another logic, it would not be very helpful and would confuse everybody…
btw. the path
file:///android_asset/ is only relevant for the webviewer to access files stored in the assets…
Of course, I have tried this first:
Runtime Error: /test.1.pdf (No such file or directory)
I hope next version will solve this and other issues/bugs
Video on how to use…copy from SD card to phone or vise versa
- Replaced path with name.Now it will find path automatically from file name (Thanks to App Inventor)
- Some other minor changes
Is there more than thank you
I have no idea about that
We need an extension of that
There is already an extension
- Added ‘recursive’ in FilesList and FileListAsync
- Fixed bug in Delete method
- Fixed bug in getting assets list using FilesList.Use
//in FilesList as dir to get Assets list while using Companion
- Some minor bug fixes
Due to this extension my automatically my mobile’s all images and videos and other files lost when i export my app and install it, I dont used this extension in blocks remains unchanged, get file path only this block is used… and after installing all data lost… if it is a bug then solve it… if it is hacked then dont use anyone…