class ImageProcess {
companion object {
fun bitmapToFile(imageBitmap: Bitmap , filename: String): File? {
val sd = Environment.getExternalStorageDirectory()
val dest = File(sd, filename)
try {
val out = FileOutputStream(dest) //problem
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
out.flush()
out.close()
} catch (e: Exception) {
e.printStackTrace()
return dest
this ERR!
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/image.jpg: open failed: EPERM (Operation not permitted)
at libcore.io.IoBridge.open(IoBridge.java:492)
W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
但我有android:requestLegacyExternalStorage="true"
。
在文件AndroidManifest.xml中
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
bitMapToFile ERR: java.io.FileNotFoundException:/storage/emulated/0/image.jpg: open failed:EPERM (Operation not permitted) in android
3
人关注