Android 华为nova7保存图片到相册失败
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)