get Album Directory on mounted media - Android Hardware

Android examples for Hardware:SD Card

Description

get Album Directory on mounted media

Demo Code


//package com.java2s;
import java.io.File;

import android.os.Environment;
import android.util.Log;

public class Main {
    private final static String TAG = "Camera4ActivityUtil";
    private static final String CAMERA_DIR = "/dcim/";

    static private File getAlbumDir() {
        File storageDir = null;//from   ww  w.j  a  va  2s  .  c o  m

        if (Environment.MEDIA_MOUNTED.equals(Environment
                .getExternalStorageState())) {

            storageDir = getAlbumStorageDir(getAlbumName());

            if (storageDir != null) {
                if (!storageDir.mkdirs()) {
                    if (!storageDir.exists()) {
                        Log.d(TAG, "failed to create directory");
                        return null;
                    }
                }
            }

        } else {
            Log.v(TAG, "External storage is not mounted READ/WRITE.");
        }

        return storageDir;
    }

    static private File getAlbumStorageDir(String albumName) {
        return new File(Environment.getExternalStorageDirectory()
                + CAMERA_DIR + albumName);
    }

    static private String getAlbumName() {
        return "MenuPhoto";
    }
}

Related Tutorials