Here you can find the source of addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)
public static Uri addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import android.content.ContentResolver; import android.content.ContentValues; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.net.Uri; import android.provider.MediaStore.Images; import android.util.Log; public class Main { private static final String TAG = "Utils"; private static final Uri IMAGE_URI = null; public static Uri addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData) { OutputStream outputStream = null; String filePath = directory + "/" + filename; try {/*from www. j a v a 2s.c o m*/ File dir = new File(directory); if (!dir.exists()) { dir.mkdirs(); Log.d(TAG, dir.toString() + " create"); } File file = new File(directory, filename); if (file.createNewFile()) { outputStream = new FileOutputStream(file); if (source != null) { source.compress(CompressFormat.JPEG, 75, outputStream); } else { outputStream.write(jpegData); } } } catch (FileNotFoundException ex) { Log.w(TAG, ex); return null; } catch (IOException ex) { Log.w(TAG, ex); return null; } finally { if (outputStream != null) { try { outputStream.close(); } catch (Throwable t) { } } } ContentValues values = new ContentValues(7); values.put(Images.Media.TITLE, name); values.put(Images.Media.DISPLAY_NAME, filename); values.put(Images.Media.DATE_TAKEN, dateTaken); values.put(Images.Media.MIME_TYPE, "image/jpeg"); values.put(Images.Media.DATA, filePath); return cr.insert(IMAGE_URI, values); } }