برای ذخیره عکس از متد زیر استفاده می کنم اما از اندروید 5 به بعد برنامه کرش میکنه مشکل کجاست؟.. ممنون
در واقع کد زیر باعث کرش میشه
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | public void save_image() { File root = android.os.Environment.getExternalStorageDirectory(); File dir = new File(root.getAbsolutePath() + "/IMAGE_TATAK" ); dir.mkdirs(); // build directory file = new File(dir, backgroundImageName); if (file.exists()) file.delete(); try { FileOutputStream outStream = new FileOutputStream(file); InputStream ims = getAssets().open( "image/" + backgroundImageName); Bitmap bitmap = BitmapFactory.decodeStream(ims); try { ims.close(); ims = null ; } catch (IOException e) {} bitmap = mark(bitmap, null ); bitmap.compress(Bitmap.CompressFormat.JPEG, 90 , outStream); outStream.flush(); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } sendBroadcast( new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse( "file://" + Environment.getExternalStorageDirectory()))); new SweetAlertDialog( this , SweetAlertDialog.SUCCESS_TYPE) .setTitleText( "Save to gallery" ) .show(); } |
1 | sendBroadcast( new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse( "file://" + Environment.getExternalStorageDirectory()))); |