Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import android.os.Environment; import android.util.Log; public class Main { public static final String TAG = "AirImagePicker"; public static File savePictureInGallery(String albumName, String prefix, byte[] fileBytes) { Log.d(TAG, "[AirImagePickerUtils] Entering didSavePictureInGallery"); long current = System.currentTimeMillis(); // Save image to album File folder = getAlbumFolder(albumName); File picture = new File(folder, prefix + "_" + current); // Write Image to File try { FileOutputStream stream = new FileOutputStream(picture); stream.write(fileBytes); stream.close(); } catch (Exception exception) { Log.d(TAG, "[AirImagePickerUtils] exception = " + exception.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (failed)"); return null; } Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (succeeded)"); return picture; } public static File getAlbumFolder(String albumName) { File folder = new File(Environment.getExternalStorageDirectory() + File.separator + albumName); if (!folder.exists()) { folder.mkdir(); try { new File(folder, ".yesmedia").createNewFile(); } catch (Exception e) { Log.d(TAG, "[AirImagePickerUtils] exception = " + e.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (failed)"); return null; } } return folder; } }