On my Samsung Galaxy S9 (Android 8.0.0), I have a removable SD card named "SD" with the following files : MyText.txt, MyPicture.jpg and History.txt.
I want to read MyText.txt and display its content, display MyPicture.jpg, and finally add text to History.txt.
However, when I attempt this, I get the following message : "the file /sdcard/MyText.txt could not be found" (and the same for History.txt and MyPicture.jpg).
I have tried multiple alternative paths, such as file:///storage/emulated/0/..., /MyText.txt (without /sdcard), and so on. I am all the more surprised as App Inventor states that : "Prefix the file name with / to read from a specific file on the SD card".
Could you please provide me with some help ?
Thank you,
A.F.
The file is stored directly on my SD card. I am using Android 8.0.0. Could you please explain what an SAF is? I am not familiar with programing.
Thank you very much for your help.
you answered immediately without reading the link...
what about first reading carefully the basics?
SAF = Storage Access Framework
I'm assuming you are talking about an non removable (emulated) sdcard...
for older devices afaik this still should work (I might be wrong, but I'm sure, @Anke will correct me then )
set the default file scope in the project properties to Legacy
and for the image try this full path file:///storage/emulated/0/MyPicture.jpg
for the file component set the file scope of the file component to Legacy and try file:///storage/emulated/0/MyText.txt
Sorry for that, I have read the article you sent me, and now better understand SAFs.
No, I am talking about a removable sdcard, hence not emulated I guess.
I tried the paths you suggested, but I get the message "file not found"...
Do I necessarily need an SAF to open, read, and write these files from my removable sdcard, or can I use only the File component on the App Inventor ?
Thank you very much for your help and your time.
The file component is not able to read from a removable sdcard, use the MFile extension together with a full path
I currently don't know, if the MFile extension is able to return the path to the removable sdcard... if not, the file extension and its AvailableStorageDirectories method can help
Thank you very much for your explanation.
I will try to see if the MFile extension could work, but is there preferentially a way to avoid using such extensions and do the same result (read a text file, write a text file, and display a picture)? For instance, by storing these files directly on the phone's "Files" ? If yes, how should I proceed and which paths should I use ?
Besides, here is the information provided for the File component :
"(Reading and) editing files on a removable SD card, Android 8"
Since Android 4.4 (API 19, KitKat) it is no longer possible to edit/save files in a removable SD card.
Thank you very much @Anke and @Taifun , it runs perfectly with the paths you suggested. I had initially not set the default file scope to "Legacy", hence the problem.