July 1, 2023
java.io.FileNotFoundException: /sdcard/Tom/green.jpg: open failed: EACCES (Permission denied)The "file not found" is misleading. The problem is access permission. The chart in the above indicate that the "rules" have changed over time for different Android versions.
You add lines that look like:
Sure enough, I look at android studio and there is a directory "manifests" that contains that file. I can double click on it in the left column and I am editing it.
Someone suggested the following process, which is all but useless. Right click above the "application" tag, and get a pull down that offers lots of options -- including "Generate", which you select. Generate offers me "XML tag" or "Copyright", choose "XML tag". If you then pick "uses-permission" you get this.
But you might as well just type in the following by hand:
ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION READ_EXTERNAL_STORAGE WRITE_EXTERNAL_STORAGEIt is useful to clarify what they mean by internal/external storage. Internal seems to mean "specific to the app that wants to access it". External seems to mean "world readable", but may or may not be a removeable
I can build the application, but it immediately dies with:
/sdcard/Tom/green.jpg: open failed: EACCES (Permission denied)So all of this has gained me nothing. This "manage files" is an even deeper permission, and more than I should need.
I would plug the phone in and it would announce on the phone "USB debugging enabled", but my project would never download and run. I switched to the shorter cable I was using previously and it "just works". I have heard various things about different USB-C cables, but apparently my long one is only partially functional.
And now my app-info page on the phone shows the Camera permission (and it is disabled when I first look at it). That page does have the ability to enable it, which I do. I don't need camera permission, but it is a way for me to see if some other permission works as expected. And it does.
It is too bad android programming isn't so much guessing and trial and error.
Some searching seems to indicate that Google made changes to how all of this works around Android 13.
int permissionCheck = ContextCompat.checkSelfPermission(PlayListActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE); if (ContextCompat.checkSelfPermission(PlayListActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // OPCIONAL(explicaciones de poque pedimos los permisos) if (ActivityCompat.shouldShowRequestPermissionRationale(PlayListActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) { } else { //pedir permisos ActivityCompat.requestPermissions(PlayListActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, permissionCheck);They had a compatibility attribute as follows, but got rid of it in Android 11 and following:
add android:requestLegacyExternalStorage="true" to theOne fellow says: "READ_EXTERNAL_STORAGE should only be requested for devices with Android 9 and below". I am not so sure about this.element in the manifest.
A book I have has a whole chapter on this in the context of the latest Android (Android 13). As I understand it, you tell Android you want to ask the user permission. Then once Android is satisfied that the user has agreed, you can do as you like.
Adventures in Computing / [email protected]