Example usage for android.os Environment getExternalStoragePublicDirectory

List of usage examples for android.os Environment getExternalStoragePublicDirectory

Introduction

In this page you can find the example usage for android.os Environment getExternalStoragePublicDirectory.

Prototype

public static File getExternalStoragePublicDirectory(String type) 

Source Link

Document

Get a top-level shared/external storage directory for placing files of a particular type.

Usage

From source file:Main.java

private static File getAlbumDir() {
    File storageDir = null;//from w w w.jav  a2s .  c o  m
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "Telegram");
        if (!storageDir.mkdirs()) {
            if (!storageDir.exists()) {
                //                    FileLog.d("tmessages", "failed to create directory");
                return null;
            }
        }
    } else {
        //            FileLog.d("tmessages", "External storage is not mounted READ/WRITE.");
    }

    return storageDir;
}

From source file:Main.java

public static String getCachePath() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()
            + File.separator + "MyCamera";
}

From source file:Main.java

public static String getOutputMediaFolderPath() {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        return null;
    }//  w ww  .  ja  v a2  s.co m

    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "HDMIRxDemo");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("CameraSample", "failed to create directory");
            return null;
        }
    }
    // return path string of the folder
    return mediaStorageDir.getAbsolutePath();
}

From source file:Main.java

public static File getLogPath(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File externalStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        if (externalStorage == null)
            return null;
        return new File(externalStorage.getPath() + File.separatorChar + "logs");
    }/* w ww  . j  a  v  a2  s  .com*/

    return null;
}

From source file:Main.java

/**
 * get the directory to save photos in/*w ww  . ja  v a  2s .  c om*/
 * @return
 */
private static File getAppDir() {
    File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    return new File(sdDir, "SjirkSudoku");
}

From source file:Main.java

/**
 * The directory of video storage used when the user wants the videos to
 * be automatically picked up by the media scanner (and visible in the
 * Gallery)./*from   w  ww .  j a v a  2 s. com*/
 */
public static File getVideosPublicDir() {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
    if (!dir.exists()) {
        dir.mkdir();
    }
    return dir;
}

From source file:Main.java

/**
 * Gets a bitmap from a path inside the TexturePoemApp-Folder
 * @param path path of the bitmap inside the TexturePoemApp-Folder
 * @return Decoded bitmap // w ww  . j a  v  a 2  s .c o  m
 */
public static Bitmap getBitmapFromPath(String path) {
    Bitmap b = null;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        String galleryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                .toString();

        File f = new File(galleryPath + "/TexturePoemApp/" + path);
        if (f.exists()) {
            b = BitmapFactory.decodeFile(f.getAbsolutePath());
        }
    }

    return b;
}

From source file:im.ene.lab.toro.sample.util.Util.java

public static File[] loadMovieFolder() throws FileNotFoundException {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
            .listFiles(new FilenameFilter() {
                @Override/*from   w w  w  .  j a  va 2 s.c om*/
                public boolean accept(File dir, String filename) {
                    return filename.endsWith(".mp4");
                }
            });
}

From source file:Main.java

public static File getAlbumDirectory(String albumName) {
    File albumDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            albumName);//from   w  w  w .j a v  a 2 s.co m
    if (!createExternalStorageDirectory(albumDir)) {
        return null;
    }
    return albumDir;
}

From source file:org.proninyaroslav.libretorrent.core.utils.FileIOUtils.java

public static String getDefaultDownloadPath() {
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
            .getAbsolutePath();/*www.j av  a  2s  . co m*/

    File dir = new File(path);
    if (dir.exists() && dir.isDirectory()) {
        return path;

    } else {
        return dir.mkdirs() ? path : "";
    }
}