Android 华为nova7保存图片到相册失败

tang1390 tang1390 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){ //表示未授权时
//进行授权
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
}
String fileName ;
File file ;
if(Build.BRAND .equals("Xiaomi") ){ // 小米手机
fileName = Environment.getExternalStorageDirectory().getPath()+"/DCIM/Camera/"+bitName ;
}else{ // Meizu 、Oppo
fileName = Environment.getExternalStorageDirectory().getPath()+"/DCIM/"+bitName ;
}
file = new File(fileName);
if(file.exists()){
file.delete();
}
FileOutputStream out;
try{
out = new FileOutputStream(file);
// 格式为 JPEG,照相机拍出的图片为JPEG格式的,PNG格式的不能显示在相册中
if(bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out))
{
out.flush();
out.close();
// 插入图库
MediaStore.Images.Media.insertImage(this.getContentResolver(), file.getAbsolutePath(), bitName, null);
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
// 发送广播,通知刷新图库的显示
this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + fileName)));
}


报错java.io.FileNotFoundException: /storage/emulated/0/DCIM/asdf.jpg: open faile EACCES (Permission denied)
...全文
评论 4
收藏 已收藏
分享
返回顶部
tang1390
Android 80,490 成员 91,375 内容