Example usage for android.content Context getExternalFilesDir

List of usage examples for android.content Context getExternalFilesDir

Introduction

In this page you can find the example usage for android.content Context getExternalFilesDir.

Prototype

@Nullable
public abstract File getExternalFilesDir(@Nullable String type);

Source Link

Document

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns.

Usage

From source file:Main.java

public static void deleteExternalStoragePrivateFile(Context appCtx, String fileName) {
    // Get path for the file on external storage.  If external
    // storage is not currently mounted this will fail.
    File file = new File(appCtx.getExternalFilesDir(null), fileName);
    if (file != null) {
        file.delete();/*from   w  w w.j  a v  a2s .  c om*/
    }
}

From source file:Main.java

/**
 * obtain /sdcard/Android/data/[packagename]/files
 *//*from ww w .java 2  s .  c  o m*/
public static String getSdFilesDir(Context context) {
    //TODO: check permission?
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File filesDir = context.getExternalFilesDir(null);
        if (filesDir != null) {
            return filesDir.getAbsolutePath();
        } else {
            return "";
        }
    } else {
        return "";
    }
}

From source file:Main.java

public static String getFile(@NonNull Context context) {
    File savedir = null;//from   w w  w .j a v  a2s  . com
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        savedir = context.getExternalFilesDir(null);
    }

    if (savedir == null) {
        savedir = context.getFilesDir();
    }

    if (!savedir.exists()) {
        savedir.mkdirs();
    }
    return savedir.getAbsolutePath();
}

From source file:com.apps.android.viish.encyclolpedia.tools.ImageManager.java

private static FileOutputStream getFileOutputStream(Context context, String fileName)
        throws FileNotFoundException {
    File path = context.getExternalFilesDir(null);
    File image = new File(path, fileName);
    return new FileOutputStream(image);
}

From source file:com.apps.android.viish.encyclolpedia.tools.ImageManager.java

private static FileInputStream getFileInputStream(Context context, String fileName)
        throws FileNotFoundException {
    File path = context.getExternalFilesDir(null);
    File image = new File(path, fileName);
    return new FileInputStream(image);
}

From source file:com.frostwire.android.gui.util.SystemUtils.java

public static File getAzureusDirectory(Context context) {
    return createFolder(context.getExternalFilesDir(null), AZUREUS_FOLDER_NAME);
}

From source file:Main.java

public static String getBitmapStoragePath(Context context) {
    String bitmapStoragePath = "";
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        try {//from www  .j  a  v  a 2s .  co m
            String root = context.getExternalFilesDir(null).getCanonicalPath();
            if (null != root) {
                File bitmapStorageDir = new File(root, APP_DIR);
                bitmapStorageDir.mkdirs();
                bitmapStoragePath = bitmapStorageDir.getCanonicalPath();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return bitmapStoragePath;
}

From source file:com.frostwire.android.gui.util.SystemUtils.java

/**
 * Iterates over all the secondary external storage roots and returns the one with the most bytes available.
 * @param context/*from  www.  ja  va2 s . c  o  m*/
 * @return
 */
public static File getBiggestSDCardDir(Context context) {
    String primaryPath = context.getExternalFilesDir(null).getParent();

    long biggestBytesAvailable = -1;

    File result = null;

    for (File f : com.frostwire.android.util.SystemUtils.getExternalFilesDirs(context)) {
        if (!f.getAbsolutePath().startsWith(primaryPath)) {
            long bytesAvailable = com.frostwire.android.util.SystemUtils.getAvailableStorageSize(f);
            if (bytesAvailable > biggestBytesAvailable) {
                biggestBytesAvailable = bytesAvailable;
                result = f;
            }
        }
    }
    //System.out.println("FW.SystemUtils.getSDCardDir() -> " + result.getAbsolutePath());
    // -> /storage/extSdCard/Android/data/com.frostwire.android/files
    return result;
}

From source file:Main.java

/**
 * Create temp file. If has external storage create in external else create
 * in internal./* ww  w.ja v a  2s  .  c o  m*/
 *
 * @param context
 * @return
 * @throws IOException
 */
public static File createTempFile(Context context) throws IOException {
    if (!hasExternalStorage()) {
        return createTempFile(context, context.getCacheDir());
    } else {
        return createTempFile(context, context.getExternalFilesDir("caches"));
    }
}

From source file:Main.java

public static File getSDDir(Context context) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        // We can read and write the media
        return context.getExternalFilesDir(null);
    } else {//from w  w w . j  a  v  a  2  s  . c  om
        // Load another directory, probably local memory
        return context.getFilesDir();
    }
}