Saves incident photos to a local storage - Android App

Android examples for App:Local Storage

Description

Saves incident photos to a local storage

Demo Code


//package com.java2s;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.util.ArrayList;

import android.content.Context;

public class Main {
    /**/*from   ww  w . ja v a  2 s .c  o m*/
     * Saves incident photos to a local storage
     * @param data - ArrayList of incident photos in form of byte[]
     * @return
     */
    public static ArrayList<File> saveIncidentPhoto(Context context,
            ArrayList<byte[]> data) {
        ArrayList<File> files = new ArrayList<File>();

        for (int i = 0; i < data.size(); i++) {
            File file = context.getFileStreamPath("incident_photo" + i
                    + ".jpeg");
            file.setReadable(true, false);
            files.add(file);

            try {
                FileOutputStream fOut = context.openFileOutput(
                        "incident_photo" + i + ".jpeg",
                        Context.MODE_WORLD_READABLE);
                fOut.write(data.get(i));
                fOut.flush();
                fOut.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return files;
    }
}

Related Tutorials