1.问题描述

Android调用相机拍照保存,然后读取保存好的照片,在读取照片时出现异常(该异常是因为没有SD卡的读取权限所致):

11-08 11:07:46.421 8539-8539/com.choosepictest D/CROP_PHOTO: /storage/emulated/0/output_image.jpg: open failed: EACCES (Permission denied)

下面是Java代码:

public void btnTakePhoto_onClick(View view)
{
picture = (ImageView)findViewById(R.id.ivPicture); // 创建File对象,用于存储拍照后的图片
File outputImage = new File(Environment.getExternalStorageDirectory(),"output_image.jpg"); try
{
if(outputImage.exists())
{
outputImage.delete();
}
outputImage.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
} imageUri = Uri.fromFile(outputImage);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent,TAKE_PHOTO);
} @Override
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
switch (requestCode)
{
case TAKE_PHOTO:
if(resultCode == RESULT_OK)
{
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(imageUri,"image/*");
intent.putExtra("scale",true);
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent,CROP_PHOTO);
}
break;
case CROP_PHOTO:
if(resultCode == RESULT_OK)
{
try
{
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
picture.setImageBitmap(bitmap);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
Log.d("CROP_PHOTO",e.getMessage());
}
}
break;
}
}

因为是权限问题,所以在AndroidManifest.xml中添加了相应权限,但是问题没有解决,下面是AndroidManifest.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.choosepictest">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application> </manifest>

2.解决方法

在往上查找了一些解决办法,基本上都是添加权限,但是权限我已经添加,问题还是没有解决,暂时没有找到解决办法。下面是网上的解决方法:

http://blog.csdn.net/zxkevin1989/article/details/7464550/

http://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android

http://stackoverflow.com/questions/26208751/filenotfoundexception-storage-emulated-0-pictures-pic-jpg-open-failed-eacces

注:上述解决办法都是正确的,是我的手机自动禁用了App的存储权限,开启权限后,问题解决。

Android学习问题记录之open failed EACCES (Permission denied)的更多相关文章

  1. android: open failed: EACCES (Permission denied)

    1.  问题描述:在Android中,用程序访问Sdcard时,有时出现“java.io.IOException: open failed: EACCES (Permission denied)&qu ...

  2. Android 6.0以后的版本报错:open failed: EACCES (Permission denied)

    Android 6.0以后的版本报错:open failed: EACCES (Permission denied) 在开发项目中,遇见要进行文件操作,遇见Caused by: android.sys ...

  3. java.io.IOException: open failed: EACCES (Permission denied)问题解决

    1.  问题描述:在Android中,用程序访问Sdcard时,有时出现“java.io.IOException: open failed: EACCES (Permission denied)&qu ...

  4. 关于 java.io.IOException: open failed: EACCES (Permission denied)

    今天解决了一个问题,不得不来和大家分享.就是关于 java.io.IOException: open failed: EACCES (Permission denied)的问题,网上也有很多人把这个问 ...

  5. 解决华为手机图片选择无效及产生的open failed: EACCES (Permission denied)错误

    在华为手机上调起图片选择时原来的效果如下 原来的代码是 Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT ...

  6. 在android 中开发java.net.SocketException: socket failed: EACCES (Permission denied) 报错

    在android中下载文件,写好下载文件的代码后需要配置相应的权限 <uses-permission android:name="android.permission.INTERNET ...

  7. Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)

    今天遇到一个项目中用到Android 6.0的系统,但是有个文件是从Assert目录下写到SDCard中,但是AndroidMinifest.xml中已经加了文件的读权限和写权限,异常日志是在创建文件 ...

  8. caused by android.system.errnoexception open failed eacces (permission denied)解决方案,安卓6.0(API23)权限问题

    在API23+以上,不止要在AndroidManifest.xml里面添加权限 <uses-permission android:name="android.permission.RE ...

  9. android中代码操作外部SD卡出错:W/System.err(1595): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)

    AndroidManifest.xml 中加上: <uses-permission android:name="android.permission.WRITE_EXTERNAL_ST ...

随机推荐

  1. IPFS星际节点网站 IPNS域名解析教程

    IPNS星际文件系统IPFS提供的域名命名空间,相当于经典HTTP协议中的DNS.只不过是,IPNS是将内容寻址的哈希值(HASH值)转换为域名,而DNS是将IP地址转换为域名. 前段时间,IPFS协 ...

  2. Java实习一

    简单的二元一次方程求解 import java.lang.Math; import java.util.Scanner; public class Solve{ public static void ...

  3. Python学习札记(十三) Function3 函数参数二

    参考:函数参数 Note A.关键字参数: 1.关键字参数:**kw 可变参数允许你传入0个或任意个参数,这些可变参数在函数调用时自动组装为一个tuple.而关键字参数允许你传入0个或任意个含参数名的 ...

  4. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...

  5. vc libcurl 模拟上传文件

    http://www.cnblogs.com/killbit/p/5393301.html 附上这篇文章,因为当时就已经想到了模拟上传,但是因为时间关系,所以就直接用PHP写了.现在改进一下,用VC+ ...

  6. mysql数据库优化课程---14、常用的sql技巧

    mysql数据库优化课程---14.常用的sql技巧 一.总结 一句话总结:其实就是sql中那些函数的使用 1.mysql中函数如何使用? 选择字段 其实就是作用域select的选择字段 3.转大写: ...

  7. C语言实现顺序表

    C语言实现顺序表代码 文件SeqList.cpp #pragma warning(disable: 4715) #include"SeqList.h" void ShowSeqLi ...

  8. Git 常用命令和 Git Flow 梳理

    git 用 git 有一段时间了,之前没有详细地了解 git flow,导致协作过程中或多或少出现了一些头疼问题.最近静下心来理了下 git flow 的整个流程,再回头看开朗了不少,总结到这里.介绍 ...

  9. Struts2中的包的作用描述

    asm-3.3.jar作用:操作java字节码的类库包路径及主要类:未提供 asm-commons-3.3.jar作用:提供了基于事件的表现形式包路径及主要类:未提供 asm-tree-3.3.jar ...

  10. SSH集成log4j日志环境

    第一步:在web.xml初始化log4j <context-param> <param-name>contextConfigLocation</param-name> ...