android.content.Context.getExternalFilesDir()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(471)

本文整理了Java中android.content.Context.getExternalFilesDir()方法的一些代码示例,展示了Context.getExternalFilesDir()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getExternalFilesDir()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getExternalFilesDir

Context.getExternalFilesDir介绍

暂无

代码示例

代码示例来源:origin: k9mail/k-9

@Override
public void init(Context context) {
  mApplicationDirectory = context.getExternalFilesDir(null);
}

代码示例来源:origin: oasisfeng/condom

@Override public File getExternalFilesDir(String type) {
  return mBase.getExternalFilesDir(type);
}

代码示例来源:origin: TeamNewPipe/NewPipe

private static File getPendingDir(@NonNull Context context) {
  //File dir = new File(ContextCompat.getDataDir(context), "pending_downloads");
  File dir = context.getExternalFilesDir("pending_downloads");
  if (dir == null) {
    // One of the following paths are not accessible ¿unmounted internal memory?
    //        /storage/emulated/0/Android/data/org.schabi.newpipe[.debug]/pending_downloads
    //        /sdcard/Android/data/org.schabi.newpipe[.debug]/pending_downloads
    Log.w(TAG, "path to pending downloads are not accessible");
  }
  return dir;
}

代码示例来源:origin: ACRA/acra

@NonNull
  @Override
  public File getFile(@NonNull Context context, @NonNull String fileName) {
    return new File(context.getExternalFilesDir(null), fileName);
  }
},

代码示例来源:origin: czy1121/update

public static void ensureExternalCacheDir(Context context) {
  File file = context.getExternalCacheDir();
  if (file == null) {
    file = new File(context.getExternalFilesDir("").getParentFile(), "cache");
  }
  if (file != null) {
    file.mkdirs();
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

RecordingSession(Context ctxt, RecordingConfig config,
         MediaProjection projection) {
 this.ctxt=ctxt.getApplicationContext();
 this.config=config;
 this.projection=projection;
 this.beeper=new ToneGenerator(
  AudioManager.STREAM_NOTIFICATION, 100);
 output=new File(ctxt.getExternalFilesDir(null), "andcorder.mp4");
 output.getParentFile().mkdirs();
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public Fragment getItem(int position) {
 File fileToEdit;
 switch(position) {
  case TAB_INTERNAL:
   fileToEdit=new File(ctxt.getFilesDir(), FILENAME);
   break;
  case TAB_EXTERNAL:
   fileToEdit=new File(ctxt.getExternalFilesDir(null), FILENAME);
   break;
  default:
   fileToEdit=
     new File(Environment.
        getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
       FILENAME);
   break;
 }
 return(EditorFragment.newInstance(fileToEdit));
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public Fragment getItem(int position) {
 File fileToEdit;
 switch(position) {
  case TAB_INTERNAL:
   fileToEdit=new File(ctxt.getFilesDir(), FILENAME);
   break;
  case TAB_EXTERNAL:
   fileToEdit=new File(ctxt.getExternalFilesDir(null), FILENAME);
   break;
  default:
   fileToEdit=
     new File(Environment.
        getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
       FILENAME);
   break;
 }
 return(EditorFragment.newInstance(fileToEdit));
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public Fragment getItem(int position) {
 File fileToEdit;
 switch(position) {
  case TAB_INTERNAL:
   fileToEdit=new File(ctxt.getFilesDir(), FILENAME);
   break;
  case TAB_EXTERNAL:
   fileToEdit=new File(ctxt.getExternalFilesDir(null), FILENAME);
   break;
  default:
   fileToEdit=
     new File(Environment.
        getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
       FILENAME);
   break;
 }
 return(EditorFragment.newInstance(fileToEdit));
}

代码示例来源:origin: jgilfelt/chuck

private static String extractDatabase(Context context) {
  try {
    File external = context.getExternalFilesDir(null);
    File data = Environment.getDataDirectory();
    if (external != null && external.canWrite()) {
      String dataDBPath = "data/" + context.getPackageName() + "/databases/chuck.db";
      String extractDBPath = "chuckdb.temp";
      File dataDB = new File(data, dataDBPath);
      File extractDB = new File(external, extractDBPath);
      if (dataDB.exists()) {
        FileChannel in = new FileInputStream(dataDB).getChannel();
        FileChannel out = new FileOutputStream(extractDB).getChannel();
        out.transferFrom(in, 0, in.size());
        in.close();
        out.close();
        return extractDB.getAbsolutePath();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

logger.log(Level.FINE, "ExternalStorageState: {0}", state);
if (state.equals(Environment.MEDIA_MOUNTED)) {
  storageFolder = view.getContext().getExternalFilesDir(null);
  storageFolders.put(type, storageFolder);

代码示例来源:origin: gzu-liyujiang/AndroidPicker

/**
 * 各种类型的文件的专用的保存路径,以“/”结尾
 *
 * @return 诸如:/mnt/sdcard/Android/data/[package]/files/[type]/
 */
public static String getExternalPrivatePath(Context context, String type) {
  File file = null;
  if (externalMounted()) {
    file = context.getExternalFilesDir(type);
  }
  //高频触发java.lang.NullPointerException,是SD卡不可用或暂时繁忙么?
  String path = "";
  if (file != null) {
    path = FileUtils.separator(file.getAbsolutePath());
  }
  LogUtils.verbose("external storage private path: " + path);
  return path;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getExternalFilesDir_shouldCreateDirectory() throws Exception {
 assertThat(context.getExternalFilesDir(null).exists()).isTrue();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getExternalFilesDir_shouldCreateNamedDirectory() throws Exception {
 File f = context.getExternalFilesDir("__test__");
 assertThat(f.exists()).isTrue();
 assertThat(f.getAbsolutePath()).endsWith("__test__");
}

代码示例来源:origin: LitePalFramework/LitePal

String path = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/";
dbFile = new File(path + dbName);
boolean result = dbFile.delete();

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = LOLLIPOP)
public void startStopTracingSamplingShouldWriteFile() {
 Debug.startMethodTracingSampling(TRACE_FILENAME, 100, 100);
 Debug.stopMethodTracing();
 assertThat(new File(context.getExternalFilesDir(null), TRACE_FILENAME).exists()).isTrue();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void startStopTracingShouldWriteFile() {
 Debug.startMethodTracing(TRACE_FILENAME);
 Debug.stopMethodTracing();
 assertThat(new File(context.getExternalFilesDir(null), TRACE_FILENAME).exists()).isTrue();
}

代码示例来源:origin: LitePalFramework/LitePal

String dbName = litePalAttr.getDbName();
if ("external".equalsIgnoreCase(litePalAttr.getStorage())) {
  dbName = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/" + dbName;
} else if (!"internal".equalsIgnoreCase(litePalAttr.getStorage()) && !TextUtils.isEmpty(litePalAttr.getStorage())) {

代码示例来源:origin: DaxiaK/MyDiary

/**
 * Create diary  dir file manager
 */
public FileManager(Context context, long topicId, long diaryId) {
  this.mContext = context;
  this.fileDir = mContext.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + topicId + "/" + diaryId + "/");
}

代码示例来源:origin: GcsSloop/diycode

/**
 * @param context    上下文
 * @param customPath 自定义路径
 * @return 内存卡文件目录
 */
public static String getExternalFileDir(Context context, String customPath) {
  String path = context.getExternalFilesDir("") + formatPath(customPath);
  mkdir(path);
  return path;
}

相关文章

Context类方法