Context getExternalFilesDir - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context getExternalFilesDir method.

This code example shows how to use the following methods:getExternalFilesDir, getFilesDir
    } 
 
    private static String scriptsDirName(Context context) {
        File storageDir = null;
        if (isDebugBuild()) { 
            storageDir = context.getExternalFilesDir(null);
            if (storageDir == null || (!storageDir.exists() && !storageDir.mkdirs())) {
                Log.e("Development mode active, but sdcard is not available.  Make sure you have added\n<uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE' />\nto your AndroidManifest.xml file.");
                storageDir = context.getFilesDir();
            } 
        } else { 
            storageDir = context.getFilesDir();
        } 
        return storageDir.getAbsolutePath() + "/scripts";
    } 
 
    private static void setDebugBuild(Context context) {
        PackageManager pm = context.getPackageManager();
        PackageInfo pi;
        try { 
7
CodeRank
This code example shows how to use the following methods:getExternalFilesDir
    assertThat(context.fileList()).isEqualTo(context.getFilesDir().list());
  } 
 
  @Test 
  public void getExternalFilesDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getExternalFilesDir(null).exists());
  } 
 
  @Test 
  public void getExternalFilesDir_shouldCreateNamedDirectory() throws Exception { 
    File f = context.getExternalFilesDir("__test__");
    assertTrue(f.exists());
    assertTrue(f.getAbsolutePath().endsWith("__test__"));
  } 
 
  @Test 
  public void getDatabasePath_shouldCreateDirectory() { 
    assertFalse(ShadowContext.DATABASE_DIR.exists()); 
    String testDBName = "abc.db";
    File dbFile = context.getDatabasePath(testDBName);
6
CodeRank
This code example shows how to use the following methods:getExternalFilesDir, getFilesDir
    } 
 
    private static String scriptsDirName(Context context) {
        File storageDir = null;
        if (isDebugBuild()) { 
            storageDir = context.getExternalFilesDir(null);
            if (storageDir == null || (!storageDir.exists() && !storageDir.mkdirs())) {
                Log.e("Development mode active, but sdcard is not available.  Make sure you have added\n<uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE' />\nto your AndroidManifest.xml file.");
                storageDir = context.getFilesDir();
            } 
        } else { 
            storageDir = context.getFilesDir();
        } 
        return storageDir.getAbsolutePath() + "/scripts";
    } 
 
    private static void setDebugBuild(Context context) {
        PackageManager pm = context.getPackageManager();
        PackageInfo pi;
        try { 
7
CodeRank

Related Context getExternalFilesDir Questions & Answers:

getExternalFilesDir Method Overview
Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.getExternalStorageDirectory()) where the application can place persistent files it owns.
See Code Examples for other Android Context Methods: