Access Download folder on Android 10 - android

I have a working code that exports some files in the Downloads folder. I'm using requestLegacyExternalStorage to be able to access the folder on Android 10-. Everything works.
Since Google Play Store requested to remove the flag
requestLegacyExternalStorage="true"
I have tried to remove it. I don't need to migrate anything so it has been relatively simple and it works fine on Android 9- and Android 11. On Android 10 it does not work. The app crashes with
android.system.ErrnoException: open failed: EACCES (Permission denied)
In the AndroidManifest I have:
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="29"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
I have granted permission to access the external store.
The crash happens when I call:
destination.outputStream()
where destination is a file in the Downloads folder.
What should I do? Why doesn't this work on Android 10 only?

The issue on Android 10, because you set in In the AndroidManifest : android:maxSdkVersion="29".
Android 10 is API level 29.
add in AndroidMainfest
in application node
android:requestLegacyExternalStorage="true"

Related

How to migrate an app in flutter from android 12 to android 13?

I need to migrate my application from android 12 to android 13 since in android 12 it does not show any errors, however when testing the app on a device with android 13 it gives me the following error:
[MethodChannelFilePicker] Platform exception:
PlatformException(read_external_storage_denied, User did not allow
reading external storage, null, null).
I've tried adding validations in the manifest, like the ones in:
I have also tried adding these validations in the main:
Add the following permission in your manifest.xml inside
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If it still does not work out, upgrade or change the package you use for picking files and check the documentation.
recommended : https://pub.dev/packages/file_picker/versions/5.2.5

react-native-fs ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/ after reinstall

Hello everyone
Environment :
Android 11
react-native 0.68.5
react-native-fs 2.20.0
Need:
Save files persistent to the application (if I uninstall the application the files need to persist). If I reinstall the application I need to be able to manipulate these files again. I uploaded the files in the download folder with RNFS.DownloadDirectoryPath so that they are not deleted when the application is uninstalled but the files are public and can be downloaded to another location if needed.
Error:
Everything works perfectly until I uninstall and reinstall the application. As soon as I want to manipulate an existing file in my /storage/emulated/0/Download/AppName/...
I encounter the following error when I want to move file :
Error: ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/AppName/...
I encounter the following error when I want to download file :
Error: ENOENT: no such file or directory, open '/storage/emulated/0/Download
Before manipulating a file I make sure I have the :
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
My build.gradle :
buildToolsVersion = "31.0.0"
minSdkVersion = 30
compileSdkVersion = 31
targetSdkVersion = 31
My manifest :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
....
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
...
A big thank you to the people who will take their time to help me
To try to solve the problem I added this line in my manifest :
android:preserveLegacyExternalStorage="true"
and I changed the minSdkVersion in my build.gradle from 21 to 30.
I have the impression that the rights belonged to the application as if by reinstalling the application it lost its rights.
You did not tell it but this happens to you on Android 11+ devices.
On Android 11+ an app has only access to the files it created itself and media files in public directories.
After reinstall an app is considered a different app.
Use Storage Access Framework ACTION_OPEN_DOCUMENT to let the user pick the files.

What happens when I request WRITE_STORAGE in Android 11?

I upgraded my app to API 30 recently. I used Mediastore to handle all of my image and video files (Scoped storage), no longer depend on WRITE_EXTERNAL_STORAGE permission. But I forgot to restrict the permission to 28.
So instead of this,
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28">
It looks like this
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE">
We aren't releasing a new version of the app until Nov 1,2021 which is Google's deadline for all the apps to be in API 30. My question is, Will there be an issue on Nov 1 as I didn't add android:maxSdkVersion in my Manifest file or will it be ignored?

Marshmallow cannot load images from lazylist file

Hello i have different images i am loading these images from server using lazy list but its working fine below 6.0 version when i run the same code on 6.0 version its throws exception
java.io.FileNotFoundException: /storage/emulated/0/LazyList/-1246063373: open failed: ENOENT (No such file or directory)
permissions are
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Anyone please help me why i am getting this exception in 6.0 version
Now for Marshmallow(API Level 23) you need to use run time permission to access contacts or load images from gallery etc etc. You need to check it by run time. You can check below link which provide library and sample project.
https://github.com/tajchert/Nammu

Android 5(HTC) EACCES (Permission denied)

app can't create folder/file on android 5(HTC HTC6525LVW os version: 5.0.1) external storage in directory owned by app.
Parent folder is returned by [getExternalFilesDirs(String type)][1] method.
Sdcard is mounted.
Anyone else having this problem or suggestion how to solve it?
(Unfortunately I don't have this device to test it more)
Edit: From one user I know that prior this bug she encrypted sdcard and then formatted it.
Some potential ideas as to what caused it:
If the phone is running in USB Storage mode when connected to your computer you can still deploy/debug like normal but write operations will fail
You were missing a permission: in your manifest file you should check to see if you have <permission name=”android.permission.WRITE_EXTERNAL_STORAGE” >
Permissions in the wrong location: make sure that your permission tag (in manifest) is located outside of the application
Writing to the data folder can cause issues like this so make sure you're writing to sdcard and not data
This is everything I could think of. Hope it helps :)
Add permission to your manifest.xml file permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Categories

Resources