简体   繁体   中英

FileNotFoundException when saving bitmap onto SD card

I tried to save "viewBitmap" into SD card.

Here is my code:

try{
String mPath = Environment.getExternalStorageDirectory().toString();
imageFile = new File(mPath, "/snapshot.png");
FileOutputStream outputStream = new FileOutputStream(imageFile);
viewBitmap.compress(Bitmap.CompressFormat.JPEG,100,outputStream);
outputStream.flush();
outputStream.close();
Toast.makeText(Share.this, "Collage was saved.",Toast.LENGTH_SHORT).show();
}catch(Throwable e) {
 e.printStackTrace();
}

At the line "FileOutputStream outputStream = new FileOutputStream(imageFile);", an exception was thrown:

在此处输入图片说明

In your AndroidManifest.XML file did you add permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

If the device is running Android 6.0 (API level 23) or higher, and the app's targetSdkVersion is 23 or higher, refer to the documentation to request the permission at run time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM