I am trying to delete a file on an external SD storage in android by using the following code:
filename = "/storage/extSdCard/AAA/testtitle.mp3"
File file = new File(filename)
file.delete()
I am also using the two permissions
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in the Manifest (outside the application declaration), and I am using the code suggested here. The device does not seem to be a Marshmellow device (first answer), and the suggested solution in the third answer also does not help. I still get the same error:
remove failed: EACCES (Permission denied) : /storage/extSdCard/AAA/testtitle.mp3
What else can I try?
Related
I was trying to read from a file I pushed to external app private folder
In my manifest I also declared all 3 storage related permission
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
and also I already granted all files access permission in the app setting page:
However, when I tried to read the file via File api, it still fails with permission error:
val file = File(context.getExternalFiles(null)).absolutePath, "test.json")
val fileStream = FileInputStream(file)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.jetbrains.handson.mpp.myapplication/files/test.json: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:492)
My understanding is that since its a app private folder , the app should always has access to it when permission is granted. However, it does not work. And I dont believe its a scope storage issue since I already granted access to all files, not just media.
Thanks!
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"
This question already has answers here:
java.io.FileNotFoundException: (Permission denied) when writing an object using ObjectOutputStream
(3 answers)
Closed 4 years ago.
Android can't open file with FileNotFoundException(Permission denied), but PermissionRead is granted.
java.io.FileNotFoundException: /mnt/obb/"file detailed path": open
failed: EACCES (Permission denied)
obb file is ERROR_ALREADY_MOUNTED.
int readPermission = ContextCompat.checkSelfPermission(activity, mPermissions[0]);
int writePermission = ContextCompat.checkSelfPermission(activity, mPermissions[1]);
readPermission == 0;
writePermission == 0;
PermissionRead is granted.
Manifest.xml
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
Android OS ver.6.0 device.
why...?
Try to give runtime permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
have you implemented runtime permission?,
first you grant manually storage permission from settings and check exception occur or not, if not then you have mistake in permission implementation.
Thank you for answers...
This is a very strange phenomenon.
Once, I was able to fix it to work properly.
Conclusion: Solution
Create an obb file with jobb command with the same name as renamed on Google Play side.
That is...Before the fix was done like this.(example)
jobb -pn com.test.testapp -pv 1 -d ./myfiles -o main1.obb
And if you upload "main1.obb" to Google Play, "main.1.com.test.testapp.obb" will be downloaded along with apk download.
But this is not good.
After the correction, it was programmed like this.
jobb -pn com.test.testapp -pv 1 -d ./myfiles -o main.1.com.test.testapp.obb
Why: Reasons to fix
I thought that there was a problem with obb mount when the following error occurred:
java.io.FileNotFoundException: /mnt/obb/"file detailed path": open failed: EACCES (Permission denied)
So I tried to unmount obb after the error.
Then an error came back.
public static final int ERROR_PERMISSION_DENIED = 25;
If I try to unmount an already mounted obb, it is a permission error.
This is strange.
As I looked it up on the Internet, the problem is obb filename made with the jobb command? Or package name? It was said that it occurred.
Therefore, I changed the obb file name generated by the jobb command.
There is no problem with this. Of course, "READ_EXTERNAL_STORAGE" has always acquired.
I did not understand anything more.
Just the application is working correctly.
Thank you.
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
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" />