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. 24,25-request对象

    var http = require('http'); var server = http.createServer(); server.listen() console.log(server.add ...

  2. 9.深入理解AbstractQueuedSynchronizer(AQS)

    1. AQS简介 在上一篇文章中我们对lock和AbstractQueuedSynchronizer(AQS)有了初步的认识.在同步组件的实现中,AQS是核心部分,同步组件的实现者通过使用AQS提供的 ...

  3. 关于mybatis mapper.xml中的if判断

    场景: 页面上有搜索框进行调节查询,不同搜索框中的内容可以为空. 过程: 点击搜索,前端把参数传给后台,这是后台要把为空的参数过滤掉. 做法: 通常我们在dao层即mapper.xml中进行过滤判断操 ...

  4. VS的 X64下的汇编编译

    参考博客 VS编译64位汇编时报错:error C4235: 使用了非标准扩展: 不支持在此结构上使用“_asm”关键字 在用VS2013编译内联汇编时,报如下错误: 错误    5    error ...

  5. 【error】: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

    错误描述如下: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ...

  6. Linux 文件与目录管理,Linux系统用户组的管理

      一.Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什 ...

  7. JS种正则表达式的基础用法

    基础语法 元字符 常用元字符 含义 . 匹配除换行符以外的任意字符 \w 匹配字母数字或下划线 \W 匹配不是字母.数字.下划线的字符 \d 匹配数字,相当于[0-9] \D 匹配不是数字的字符 \s ...

  8. 二十二、utl_inaddr(用于取得局域网或Internet环境中的主机名和IP地址)

    1.概述 作用:用于取得局域网或Internet环境中的主机名和IP地址. 2.包的组成 1).get_host_name作用:用于取得指定IP地址所对应的主机名语法:utl_inaddr.get_h ...

  9. 缓存LruCache简单创建和使用

    LruCache一般使用: /** * 总容量为当前进程的1/8,单位:KB * sizeOf():计算缓存对象的大小,单位要一致 * entryRemoved():移除旧缓存时调用 */ int m ...

  10. HDU 5875 Function (线段树+gcd / 单调栈)

    题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对数字b取模时:如果a<b,则等于原数,否则a会变小至少一半. ...