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 File getPDFFileLink(Context context, String fileLink) {
    return new File(new File(context.getExternalFilesDir(null), "pdf"), fileLink.hashCode() + ".pdf");
}

From source file:Main.java

/**
 * Return the directory where the generated tlogs logging files are stored.
 * @return File to the tlogs directory/*from   w  w  w  .  j  a  v  a2s.  c o  m*/
 */
private static File getTLogsDirectory(Context context) {
    File tlogDir = new File(context.getExternalFilesDir(null), DIRECTORY_TLOGS);
    if (!tlogDir.isDirectory()) {
        tlogDir.mkdirs();
    }

    return tlogDir;
}

From source file:Main.java

public static boolean hasExternalStoragePrivateFile(Context appCtx, String fileName) {

    File file = new File(appCtx.getExternalFilesDir(null), fileName);
    return file.exists();
}

From source file:Main.java

static public boolean hasReceiptImage(Context ctxt, int tripId, String imgName) {
    File file = new File(ctxt.getExternalFilesDir(null) + "/" + tripId, imgName);
    return file.exists();
}

From source file:Main.java

public static File getDownloadDir(Context context) {
    return isExternalStorageWritable() ? context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
            : context.getFilesDir();//from  ww  w.  j ava 2 s  .c  o m
}

From source file:Main.java

public static File getLocalBackupFolder(Context context) {
    File rootFolder = new File(context.getExternalFilesDir(null) + File.separator + "backup");
    rootFolder.mkdirs();//from ww w  . ja va 2  s  .  c  o  m
    return rootFolder;
}

From source file:Main.java

public static File getOutputMediaFile(Context mContext) {
    File mediaStorageDir = mContext.getExternalFilesDir(cacheCampareImage);
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }/*from w w  w .j a v a 2  s  .  c o  m*/
    }
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;

    mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    return mediaFile;
}

From source file:Main.java

static public void deleteReceiptImage(Context ctxt, int tripId, String imgName) {
    File file = new File(ctxt.getExternalFilesDir(null) + "/" + tripId, imgName);
    if (file.exists()) {
        boolean test = file.delete();
        assert test;
    }//  w  ww .j a va2  s  .  com
}

From source file:Main.java

public static Pair<Boolean, Uri> isTrackExist(Context context, String artist, String track) {
    File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_MUSIC),
            artist + " - " + track + ".mp3");
    return new Pair<>(file.exists(), Uri.fromFile(file));
}

From source file:Main.java

public static void logGlobalException(Context c, String[] logs) {
    String dir = c.getExternalFilesDir(null).getParent();
    try {// ww w  . ja  v a 2 s  .  c om
        File file = new File(dir + "/error_logs.log");
        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(file, true);

        for (String log : logs) {
            fos.write((log + "\n\n").getBytes());
        }
        fos.close();
    } catch (IOException ioe) {
        Log.e("AndroidUtils", "An exception has occured in logGlobalException!");
        ioe.printStackTrace();
    }
}