save Image To Gallery - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

save Image To Gallery

Demo Code

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;

public class Main {

  /**//from  w  w  w  .  j a  v a2s .c  o m
   * The drawable objects into bitmap and then saved to Gallery, If you need to
   * immediately send a broadcast display at the Gallery
   * 
   * @param context
   * @param drawable
   * @param picName
   * @return
   */
  public static String saveImageToGallery(Context context, Drawable drawable, String picName) {
    Bitmap bitmap = null;// drawableToBitmap(drawable);

    String result = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, picName, "");
    if (result == null) {
      return null;
    }
    context.sendBroadcast(
        new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    return "";

  }

}

Related Tutorials