Android Question Reading Folders

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to All.
After many unsuccessful trials, I decided to submit to the community my problem which concerns accessing a File.DirRootExternal subfolder. Of course, my old apps worked well before, while now they crash with:

java.io.FileNotFoundException: /storage/emulated/0/Smas/ListaCaixaN_UTF-8.txt: open failed: EACCES (Permission denied)

This topic is treated many times in this forum, and apparently definitive workarounds exist. I have followed these workarounds, added permission requests to Manifest and used the top information existing here, namely an Erel post, concerning the access to DirRootExternal. I attach a project showing what I did. The background is: I need to pre-load one or more files to be read by the App. The ideal place for such files is not the Folder related to the App itself, namely: Internal_Memory/Android/data/App_related_folder/files/. This folder is destroyed if the App is uninstalled (correct me is wrong). The ideal place is a folder which must be accessible also by other Apps and survive to eventual uninstallation. Therefore, connecting the Phone with a cable to the computer, I created a folder as in the attached picture. The folder name is "Smas". Then I copied an ascii txt file inside that folder (not attached, but not important: any file may be used). Trying to access the file, with the attached project, fails.
Moreover the workaround to use RuntimePermission.GetSafeDefaultDir instead of FileDirRootExternal has another drawback: while the subfolders are accessible with a cable connection, the same is not true running an Ftp server on the phone (at least this is my impression). So, in practice, I can manage the pre-loaded files there, with the cable, but not with Ftp. Even, with Ftp connection, it seems that the subfolders internal to the" Android/data/App_related_Folder/files" are not visible. The "Android/Data" folder appears to be empty.
Thanks in advance.
 

Attachments

  • Problem.png
    57.9 KB · Views: 91
  • UpDown.zip
    9.2 KB · Views: 80

DonManfred

Expert
Licensed User
Longtime User
You do not have accesss to DirRootExternal!

You need to use the ExternalStorage-Class when working with this Folder (under higher Androids)

See also
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi Manfred. Thanks. BUT I used Erel's suggestion which was clear. So, it is no longer valid, I guess. Besides this, anyway, does the geniuses of Android (forgive me, I am a little upset) imagine that some poor programmer may need an humble folder to be freely accessed by anyone? (Without loosing hours or days...). Does this possibility exist? The use of GetSafeDir etc. has some drawbacks, as I wrote..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
By the way, reading your second link, I did a change in the manifest:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>

putting 29 instead of 30, like before. The App doesn't crash. I am not so expert to understand the reasons, but is this so simple ?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Up to target SDK 29 it's possible to use the Manifest workaround to access File DirRootExternal.
From SDK 30 this is no more possible.
If your app will not be published on Google Play you can stick to 29 or lower.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…