android.content.Context#getFilesDir ( )源码实例Demo

下面列出了android.content.Context#getFilesDir ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: clevertap-android-sdk   文件: FileUtils.java
public static void deleteFile(Context context, CleverTapInstanceConfig config, String fileName) throws Exception {
    if (TextUtils.isEmpty(fileName) || context == null)
        return;
    try {
        File file = new File(context.getFilesDir(), fileName);
        if (file.exists()) {
            if (file.delete()) {
                if (config != null)
                    config.getLogger().verbose(config.getAccountId(), "File Deleted:" + fileName);
            } else {
                if (config != null)
                    config.getLogger().verbose(config.getAccountId(), "Failed to delete file" + fileName);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (config != null)
            config.getLogger().verbose(config.getAccountId(), "writeFileOnInternalStorage: failed" + fileName + " Error:" + e.getLocalizedMessage());
    }
}
 
源代码2 项目: HPlayer   文件: FileManager.java
/**
 * 保存
 */
public static boolean saveData(Context context, Serializable serializable, String fileName) {
    if (serializable == null || TextUtils.isEmpty(fileName)) {
        return false;
    }
    try {
        File file = new File(context.getFilesDir(), fileName);
        if (!file.exists()) {
            file.createNewFile();
        }
        return saveSerializable(serializable, file);

    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
 
源代码3 项目: Kalle   文件: FileUtils.java
public static File getAppRootPath(Context context) {
    if (sdCardIsAvailable()) {
        return Environment.getExternalStorageDirectory();
    } else {
        return context.getFilesDir();
    }
}
 
源代码4 项目: PingHeart   文件: Settings.java
private synchronized static boolean deleteLocalFile(Context context, String filename){
    File file = new File(context.getFilesDir(), filename);
    boolean success = false;
    try {
        if (file.exists())
            success = deleteFile(file);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return success;
}
 
源代码5 项目: XposedSmsCode   文件: StorageUtils.java
/**
 * 获取日志路径
 */
public static File getLogDir(Context context) {
    if (isSDCardMounted()) {
        return context.getExternalFilesDir("log");
    } else {
        return new File(context.getFilesDir(), "log");
    }
}
 
源代码6 项目: deltachat-android   文件: AccountManager.java
private File getUniqueDbName(Context context) {
    File dir = context.getFilesDir();
    int index = 1;
    while (true) {
        File test = new File(dir, String.format("messenger-%d.db", index));
        File testBlobdir = new File(dir, String.format("messenger-%d.db-blobs", index));
        if (!test.exists() && !testBlobdir.exists()) {
            return test;
        }
        index++;
    }
}
 
@Before
public void setUp() {
	Context context = InstrumentationRegistry.getTargetContext();
	accountKeystoreService = new KeystoreAccountService(new File(context.getFilesDir(), "store"),
														new File(context.getFilesDir(), ""),
														new KeyService(null));
}
 
public TestNativeReportFilesProvider(Context context) {
  final File filesDir = context.getFilesDir();
  recursiveDelete(filesDir);

  File rootFolder = new File(context.getFilesDir(), UUID.randomUUID().toString());
  rootFolder.mkdirs();

  validFiles = new File(rootFolder, UUID.randomUUID().toString());
  validFiles.mkdirs();
}
 
源代码9 项目: AndPermission   文件: FileUtils.java
public static File getFileDir(Context context, @Nullable String type) {
    File root = context.getFilesDir();
    if (TextUtils.isEmpty(type)) {
        return root;
    } else {
        File dir = new File(root, type);
        createDir(dir);
        return dir;
    }
}
 
源代码10 项目: AndroidStudyDemo   文件: CrashHandler.java
/**
 * 获取错误报告文件名
 * @param context
 * @return
 */
private String[] getCrashReportFiles(Context context) {
    File filesDir = context.getFilesDir();
    // 实现FilenameFilter接口的类实例可用于过滤器文件名
    FilenameFilter filter = new FilenameFilter() {
        // accept(File dir, String name)
        // 测试指定文件是否应该包含在某一文件列表中。
        public boolean accept(File dir, String name) {
            return name.endsWith(CRASH_REPORTER_EXTENSION);
        }
    };
    // list(FilenameFilter filter)
    // 返回一个字符串数组,这些字符串指定此抽象路径名表示的目录中满足指定过滤器的文件和目录
    return filesDir.list(filter);
}
 
源代码11 项目: dhis2-android-sdk   文件: FileResourceUtil.java
static File renameFile(File file, String newFileName, Context context) {
    String contentType = URLConnection.guessContentTypeFromName(file.getName());
    String generatedName = generateFileName(MediaType.get(contentType), newFileName);
    File newFile = new File(context.getFilesDir(), "sdk_resources/" + generatedName);

    if (!file.renameTo(newFile)) {
        Log.d(FileResourceUtil.class.getCanonicalName(),
                "Fail renaming " + file.getName() + " to " + generatedName);
    }
    return newFile;
}
 
源代码12 项目: JobSchedulerCompat   文件: JobStore.java
public static JobStore initAndGet(Context context) {
    synchronized (sSingletonLock) {
        if (sSingleton == null) {
            sSingleton = new JobStore(context, context.getFilesDir());
        }
        return sSingleton;
    }
}
 
源代码13 项目: Utils   文件: ScreenShoot.java
/**
 * generate the default path for the file.
 * default file name format is: yyyyMMddHHmmss.png.
 */
private static String getDefaultPath(Context context) {
    String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".png";
    String path = context.getFilesDir() + fileName;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        path = context.getExternalCacheDir() + File.separator + fileName;
    }
    return path;
}
 
源代码14 项目: zone-sdk   文件: EnvironmentUtils.java
/**
 * 这里的文件夹已经被创建过了
 *
 * @param context
 * @param ignoreSDRemovable 可移除的sd是否无视
 * @return
 */
public static File getSmartFilesDir(Context context, boolean ignoreSDRemovable) {
    //SD卡 存在 并且不是 拔插的
    File fileResult=context.getFilesDir();
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            &&(ignoreSDRemovable || Environment.isExternalStorageRemovable())){
            File fileTemp= context.getExternalFilesDir(null);
            if(fileTemp!=null)
                 fileResult=fileTemp;//导致即使不为Null的可能
        }
    return fileResult;
}
 
源代码15 项目: ucar-weex-core   文件: Storage.java
@TargetApi(8)
private static File getExternalFilesDir(Context context) {
    if (hasFroyo()) {
        File dir1 = context.getExternalFilesDir((String) null);
        return dir1 != null ? dir1 : context.getFilesDir();
    } else {
        String dir = "/Android/content/" + context.getPackageName() + "/files";
        return new File(Environment.getExternalStorageDirectory(), dir);
    }
}
 
public static File getUploadDirectory(Context context) {
    File uploadDirectory = new File(context.getFilesDir(), "upload");
    if (!uploadDirectory.exists())
        uploadDirectory.mkdirs();
    return uploadDirectory;
}
 
源代码17 项目: BookyMcBookface   文件: Book.java
Book(Context context) {
    this.dataDir = context.getFilesDir();
    this.context = context;
    sectionIDs = new ArrayList<>();
}
 
源代码18 项目: AOSP-Kayboard-7.1.2   文件: DictionaryInfoUtils.java
/**
 * Helper method to get the top level cache directory.
 */
private static String getWordListCacheDirectory(final Context context) {
    return context.getFilesDir() + File.separator + "dicts";
}
 
源代码19 项目: YalpStore   文件: Paths.java
static public File getFilesDir(Context context) {
    if (null == filesDir) {
        filesDir = context.getFilesDir();
    }
    return filesDir;
}
 
源代码20 项目: diycode   文件: FileUtil.java
/**
 * @param context    上下文
 * @param customPath 自定义路径
 * @return 程序系统文件目录绝对路径
 */
public static String getFileDir(Context context, String customPath) {
    String path = context.getFilesDir() + formatPath(customPath);
    mkdir(path);
    return path;
}
 
 方法所在类
 同类方法