Android异常:java.io.IOException:打开失败:EACCES(权限被拒绝)[重复]

时间:2023-01-17 20:30:51

This question already has an answer here:

这个问题在这里已有答案:

For some strange reason, am constantly facing an issue with different types of Android devices, for saving the captured images on the device storage.

出于某些奇怪的原因,我经常遇到不同类型的Android设备的问题,用于将捕获的图像保存在设备存储上。

Here, is the detailed error log, of what, actually am getting.

这里是详细的错误日志,实际上是什么。

java.io.IOException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:940)
at com.parkhya.pick_for_shareAflash.HomeActivity.resizeImage(HomeActivity.java:456)
at com.parkhya.pick_for_shareAflash.HomeActivity.onActivityResult(HomeActivity.java:393)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:933)

Although, all the other Android apps, like, Instagram and others, are able to save the camera clicked images on the devices. Anybody, can you please suggest, what should I do, in order for my app, to save the camera pictures in sdcard.

虽然,所有其他Android应用程序,如Instagram和其他人,都可以保存设备上的相机点击图像。任何人,请你建议,为了我的应用程序,我应该怎么做,将相机图片保存在SD卡中。

4 个解决方案

#1


22  

please add the permission for Allows an application to write to external storage.

请添加允许应用程序写入外部存储的权限。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Allows an application to read from external storage.

允许应用程序从外部存储读取。

Any app that declares the WRITE_EXTERNAL_STORAGE permission is implicitly granted this permission.

任何声明WRITE_EXTERNAL_STORAGE权限的应用程序都会被隐式授予此权限。

This permission is enforced starting in API level 19. Before API level 19, this permission is not enforced and all apps still have access to read from external storage. You can test your app with the permission enforced by enabling Protect USB storage under Developer options in the Settings app on a device running Android 4.1 or higher.

从API级别19开始强制执行此权限。在API级别19之前,不会强制执行此权限,并且所有应用程序仍有权从外部存储读取。您可以通过在运行Android 4.1或更高版本的设备上的“设置”应用中的“开发者”选项下启用“保护USB存储”来强制执行权限来测试您的应用。

#2


21  

This may help you. I face the same issue when writing the file on sdcard. I have set all required permission to write the file but I used the file object like below:

这可能对你有所帮助。在sdcard上写文件时我遇到同样的问题。我已经设置了写入文件所需的所有权限,但我使用了如下文件对象:

Wrong:

File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+fileName);

Correct:

File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), fileName);

That means the path was wrong.

这意味着道路错了。

#3


0  

Solution what i find is

解决方案我发现的是

edit the Emulator 1. go to android virtual device manager and then edit the emulator 2. set say 100 MB for Sd card for the respected emulator and say Ok 3. save and close emulator and start 4. path saved is click DDMS mnt/sdcard/yourfilename it worked for me the app is not giving Error and is working

编辑模拟器1.转到android虚拟设备管理器,然后编辑模拟器2.为尊重的模拟器设置说100 MB的Sd卡并说出Ok 3.保存并关闭模拟器并启动4.保存的路径是单击DDMS mnt / sdcard / yourfilename它对我有用,应用程序没有给出错误并且正在工作

#4


-9  

Note the following trap: Someone else wrote

请注意以下陷阱:其他人写道

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>

in AndroidManifest.xml. I wanted to save files and added the mentioned line and got

在AndroidManifest.xml中。我想保存文件并添加提到的行并获得

<uses-permission android:name="android.permission.INTERNET" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</uses-permission>

which is bad syntax. It should be

这是不好的语法。它应该是

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

or

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

#1


22  

please add the permission for Allows an application to write to external storage.

请添加允许应用程序写入外部存储的权限。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Allows an application to read from external storage.

允许应用程序从外部存储读取。

Any app that declares the WRITE_EXTERNAL_STORAGE permission is implicitly granted this permission.

任何声明WRITE_EXTERNAL_STORAGE权限的应用程序都会被隐式授予此权限。

This permission is enforced starting in API level 19. Before API level 19, this permission is not enforced and all apps still have access to read from external storage. You can test your app with the permission enforced by enabling Protect USB storage under Developer options in the Settings app on a device running Android 4.1 or higher.

从API级别19开始强制执行此权限。在API级别19之前,不会强制执行此权限,并且所有应用程序仍有权从外部存储读取。您可以通过在运行Android 4.1或更高版本的设备上的“设置”应用中的“开发者”选项下启用“保护USB存储”来强制执行权限来测试您的应用。

#2


21  

This may help you. I face the same issue when writing the file on sdcard. I have set all required permission to write the file but I used the file object like below:

这可能对你有所帮助。在sdcard上写文件时我遇到同样的问题。我已经设置了写入文件所需的所有权限,但我使用了如下文件对象:

Wrong:

File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+fileName);

Correct:

File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), fileName);

That means the path was wrong.

这意味着道路错了。

#3


0  

Solution what i find is

解决方案我发现的是

edit the Emulator 1. go to android virtual device manager and then edit the emulator 2. set say 100 MB for Sd card for the respected emulator and say Ok 3. save and close emulator and start 4. path saved is click DDMS mnt/sdcard/yourfilename it worked for me the app is not giving Error and is working

编辑模拟器1.转到android虚拟设备管理器,然后编辑模拟器2.为尊重的模拟器设置说100 MB的Sd卡并说出Ok 3.保存并关闭模拟器并启动4.保存的路径是单击DDMS mnt / sdcard / yourfilename它对我有用,应用程序没有给出错误并且正在工作

#4


-9  

Note the following trap: Someone else wrote

请注意以下陷阱:其他人写道

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>

in AndroidManifest.xml. I wanted to save files and added the mentioned line and got

在AndroidManifest.xml中。我想保存文件并添加提到的行并获得

<uses-permission android:name="android.permission.INTERNET" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</uses-permission>

which is bad syntax. It should be

这是不好的语法。它应该是

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

or

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />