简体   繁体   English

Android - FileNotFoundException 打开失败:EACCES(权限被拒绝)

[英]Android - FileNotFoundException open failed: EACCES (Permission denied)

I have an application that in the login I download images from my server.我有一个应用程序,在登录时我从我的服务器下载图像。 in the first login, everything is work fine but when I uninstall the application and install it again I get this exception:在第一次登录时,一切正常,但是当我卸载应用程序并再次安装时,出现此异常:

java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.gilapp.android.app/files/images/book_118.png: open failed: EACCES (Permission denied) java.io.FileNotFoundException:/storage/emulated/0/Android/data/com.gilapp.android.app/files/images/book_118.png:打开失败:EACCES(权限被拒绝)

and can't save the image.并且无法保存图像。

this happen while I'm trying to create output stream:当我尝试创建输出流时会发生这种情况:

OutputStream output = new FileOutputStream(filePath);

The images download fine just when I do the second installation after I go to App info -> Storage -> clear data转到应用信息-> 存储-> 清除数据后进行第二次安装时,图像下载正常

Another important point is that it happens only in Samsung's tablet: SM-T800 (API level 23)另一个重要的一点是它只发生在三星的平板电脑上: SM-T800 (API level 23)

In other devices it's not happening, the devices that I test: Samsung SM-G900H (API level 23) , Asus P028 (API level 24) , Samsung SM-G950F (API level 28)在其他设备中它没有发生,我测试的设备: Samsung SM-G900H (API level 23)Asus P028 (API level 24)Samsung SM-G950F (API level 28)

If your app is pointing to the android version 10.如果您的应用指向 android 版本 10。

In the manifest include under the application add在清单中包含在应用程序下添加


android:requestLegacyExternalStorage="true"


Note that this workaround no longer works in Android 11.请注意,此解决方法不再适用于 Android 11。

You need to get Run-time permission for write in storage.您需要获得写入存储的 运行时权限 before saving your files check the permission.also there are some library for this work: Android-Arsenal在保存文件之前检查权限。还有一些用于这项工作的库: Android-Arsenal

is better to use a FileProvider for accessing files in storage.最好使用FileProvider来访问存储中的文件。

When you uninstall your application all files in getExternalFilesDir() are removed hence the /images directory has gone当您卸载应用程序时, getExternalFilesDir()中的所有文件都将被删除,因此/images目录已消失

After reinstall you can again write files to that directory for which you do not need any permission.重新安装后,您可以再次将不需要任何权限的文件写入该目录。

Not at runtime.不是在运行时。 Not in manifest.不在清单中。

But you want them in the ..../images directory.但是您希望它们位于 ..../images 目录中。

You have to care for that directory yourself.你必须自己照顾那个目录。

Check if the directory exists and then create it before you try to put a file in it.检查目录是否存在,然后在尝试将文件放入其中之前创建它。

First, check whether you have implemented scoped storage logic in the app.首先,检查您是否在应用中实现了作用域存储逻辑。 You can also use android:requestLegacyExternalStorage="true" But this legacyStoragePermission is limited to version 10. You need to implement scoped logic.你也可以使用 android:requestLegacyExternalStorage="true" 但是这个 legacyStoragePermission 仅限于版本 10。你需要实现作用域逻辑。

Also, check whether your targetSDKVersion value is 30 or greater or not, this is needed if you are using the app in Device android version 30 or more.此外,请检查您的 targetSDKVersion 值是否为 30 或更大,如果您在 Device android 版本 30 或更高版本中使用该应用程序,则需要这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FileNotFoundException 打开失败:Android 模拟器上的 EACCES(权限被拒绝) - FileNotFoundException open failed: EACCES (Permission denied) on Android Emulator FileNotFoundException:open failed:EACCES(权限被拒绝) - FileNotFoundException: open failed: EACCES (Permission denied) io.FileNotFoundException:打开失败:EACCES(权限被拒绝) - io.FileNotFoundException: open failed: EACCES (Permission denied) java.io.FileNotFoundException:打开失败:EACCES(权限被拒绝) - java.io.FileNotFoundException: open failed: EACCES (Permission denied) java.io.filenotfoundexception 在设备上打开失败的 eacces(权限被拒绝) - java.io.filenotfoundexception open failed eacces (permission denied) on device Android打开失败:EACCES(权限被拒绝) - Android open failed: EACCES (Permission denied) 打开失败:Android中的EACCES(权限被拒绝) - Open failed: EACCES (Permission denied) in Android android kotlin java.io.FileNotFoundException:/storage/emulated/0/number.txt:打开失败:EACCES(权限被拒绝) - android kotlin java.io.FileNotFoundException: /storage/emulated/0/number.txt: open failed: EACCES (Permission denied) Android Q : java.io.FileNotFoundException: /proc/self/net/dev: open failed: EACCES (Permission denied) - Android Q : java.io.FileNotFoundException: /proc/self/net/dev: open failed: EACCES (Permission denied) Android Q openFd:java.io.FileNotFoundException:打开失败:EACCES(权限被拒绝) - Android Q openFd: java.io.FileNotFoundException: open failed: EACCES (Permission denied)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM