create Image Cache - Android android.os

Android examples for android.os:Environment

Description

create Image Cache

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Main{

    public static File createImageCache(Context context) {
        File baseFile;/*w ww.j  a  va 2  s . c o  m*/
        if (isSdCard()) {
            String packageName = context.getPackageName();
            baseFile = new File(Environment.getExternalStorageDirectory(),
                    "Android/data/" + packageName + "/files/");
        } else {
            baseFile = context.getFilesDir();
        }
        File file = new File(baseFile, IMAGE);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

}

Related Tutorials