I would like to send an email where there is a QR code attach in it. I try to save the QR code which is in Bitmap to the storage, but it always comes out with NullPointerException, no such file or directory is found. Can anyone help? Thanks a lot.
Below are my error message and my code
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try{
BitMatrix bitMatrix = multiFormatWriter.encode(key, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
//File file = BitmapSaver.saveImageToExternalStorage(AddReservationDetailActivity.this,bitmap);
File myDir = new File(Environment.getExternalStorageDirectory()+"/req_images");
myDir.mkdirs();
DateFormat format = new SimpleDateFormat("yyyy_MM_dd_H_mm_ss", Locale.getDefault());
Date curDate = new Date();
String displayDate = format.format(curDate);
String fname = displayDate+ "_Image-Report.jpg";
File file = new File(myDir,fname);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{email});
emailIntent.putExtra(Intent.EXTRA_SUBJECT,"This QR code is for your check In purpose");
emailIntent.putExtra(Intent.EXTRA_TEXT," ");
emailIntent.setType("image/*");
try{
FileOutputStream outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG,100,outputStream);
outputStream.close();
}catch(Exception ex){
ex.printStackTrace();
}
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file));
startActivity(Intent.createChooser(emailIntent,"Send the email in: "));
}catch (WriterException e){
e.printStackTrace();
}