0
private void storeImage(Bitmap image) {
    File pictureFile = getOutputMediaFile();
    if (pictureFile == null) {
       // Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage());
        return;
    }
    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        image.compress(Bitmap.CompressFormat.PNG, 90, fos);
        fos.close();
    } catch (FileNotFoundException e) {
       // Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
       // Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

I have used above code to save generated QR in Gallery. and it is working too.

But it is saving in Internal Storage/package_name/Files/mtImage.jpg.

I have to go to file manager in order to view it. I want to view it directly in Gallery and I don't have any SD card.

Please help me with this.

ADM
  • 20,406
  • 11
  • 52
  • 83

1 Answers1

0

Below code helps to save bitmap image to gallery

public static void addImageToGallery(final String filePath, final Context context) {

    ContentValues values = new ContentValues();

    values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.MediaColumns.DATA, filePath);

    context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}