The Manifest. Permission. WRITE_EXTERNAL_STORAGE)!=PackageManager. PERMISSION_GRANTED) {//said unauthorized
//for authorization
ActivityCompat. RequestPermissions (this, new String [] {the Manifest. Permission. WRITE_EXTERNAL_STORAGE}, 1);
}
The String fileName.
The File File;
If (Build) BRAND) equals (" Xiaomi ")) {//millet mobile phone
FileName=Environment. External.getexternalstoragedirectory (.) getPath () + "/DCIM/Camera/" + bitName;
} else {//Meizu, Oppo
FileName=Environment. External.getexternalstoragedirectory (.) getPath () + "/DCIM/" + bitName;
}
The file=new file (fileName);
If (the file. The exists ()) {
file.delete();
}
FileOutputStream out;
Try {
Out=new FileOutputStream (file);
//format to JPEG, camera take pictures as JPEG, PNG format cannot be shown in the photo album
If press (bitmap.com bitmap.com pressFormat. JPEG, 90, (out))
{
Out. The flush ();
out.close();
//insert gallery
MediaStore. Images. Media. InsertImage (enclosing getContentResolver (), the file. The getAbsolutePath (), bitName, null);
}
}
The catch (FileNotFoundException e)
{
e.printStackTrace();
}
The catch (IOException e)
{
e.printStackTrace();
}
//radio, notice sending refresh gallery show
Enclosing sendBroadcast (new Intent (Intent. ACTION_MEDIA_SCANNER_SCAN_FILE, Uri, parse (" file://"+ fileName)));
}
Error in Java. IO. FileNotFoundException:/storage/emulated/0/DCIM/asdf. JPG: open faile EACCES (Permission denied)
CodePudding user response:
I guess it was 6.0 7.0 8.0 for mobile phone memory card address problems, the answer to your search path above 6.0 read a tryCodePudding user response: