下面列出了android.app.Application#getFilesDir ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static String getReactDir(Application application){
return application.getFilesDir()+ File.separator+jsState.reactDir+File.separator;
}
public static boolean checkLoadKernalDebugPatch(Application application) {
if (Build.VERSION.SDK_INT < 21) {
//暂时只支持art设备的debug调试
return false;
}
boolean loadKernalPatch = false;
try {
ApplicationInfo app_info = application.getApplicationInfo();
boolean debug = (app_info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
if (debug) {
File debugBundleDir = new File(KernalConstants.baseContext.getExternalFilesDir("debug_storage"), KERNAL_BUNDLE_NAME);
File patchFile = new File(debugBundleDir, "patch.zip");
if (patchFile.exists()) {
loadKernalPatch = true;
KernalBundle bundle = new KernalBundle();
//DexFile dexFile = (DexFile) KernalConstants.dexBooster.loadDex(KernalConstants.baseContext, KernalConstants.baseContext.getApplicationInfo().sourceDir,
// new File(patchFile.getParent(), "base.dex").getAbsolutePath(), 0, true);
File internalDebugBundleDir = new File(new File(application.getFilesDir(), "debug_storage"), KERNAL_BUNDLE_NAME);
internalDebugBundleDir.mkdirs();
DexFile patchDexFile = (DexFile) DexFile.loadDex(patchFile.getAbsolutePath(),new File(internalDebugBundleDir, "patch.dex").getAbsolutePath(), 0);
if (bundle.needReplaceClassLoader(application)) {
NClassLoader loader = new NClassLoader(".", KernalBundle.class.getClassLoader().getParent());
try {
NClassLoader.replacePathClassLoader(KernalConstants.baseContext, KernalBundle.class.getClassLoader(), loader);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
bundle.installKernalBundle(KernalConstants.baseContext.getClassLoader(), patchFile, new DexFile[]{patchDexFile/*, dexFile*/}, null,
true /*(app_info.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0*/);
bundle.prepareRuntimeVariables(application);
Class DelegateResourcesClazz = application.getClassLoader().loadClass("android.taobao.atlas.runtime.DelegateResources");
DelegateResourcesClazz.getDeclaredMethod("addApkpatchResources", String.class)
.invoke(DelegateResourcesClazz, patchFile.getAbsolutePath());
Toast.makeText(KernalConstants.baseContext, "当前处于DEBUG调试状态,不支持动态更新,清除数据可恢复", Toast.LENGTH_LONG).show();
}
}
} finally {
return loadKernalPatch;
}
}
@NonNull
public static File getBookmarkPage(@NonNull Application application, @Nullable String folder) {
String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : "";
return new File(application.getFilesDir(), prefix + FILENAME);
}
@NonNull
public static File getStartPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
@NonNull
private static File getDownloadsPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
@NonNull
public static File getBookmarkPage(@NonNull Application application, @Nullable String folder) {
String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : "";
return new File(application.getFilesDir(), prefix + FILENAME);
}
@NonNull
public static File getStartPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
@NonNull
private static File getDownloadsPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
/**
* Use this method to delete the bundle with the specified name.
* This is a blocking call and should be used within a worker
* thread unless immediate deletion is necessary.
*
* @param app the application object needed to get the file.
* @param name the name of the file.
*/
public static void deleteBundleInStorage(final @NonNull Application app, final @NonNull String name) {
File outputFile = new File(app.getFilesDir(), name);
if (outputFile.exists()) {
outputFile.delete();
}
}
/**
* Use this method to delete the bundle with the specified name.
* This is a blocking call and should be used within a worker
* thread unless immediate deletion is necessary.
*
* @param app the application object needed to get the file.
* @param name the name of the file.
*/
public static void deleteBundleInStorage(final @NonNull Application app, final @NonNull String name) {
File outputFile = new File(app.getFilesDir(), name);
if (outputFile.exists()) {
outputFile.delete();
}
}
/**
* Get the file that the history page is stored in
* or should be stored in.
*
* @param application the application used to access the file.
* @return a valid file object, note that the file might not exist.
*/
@NonNull
private static File getHistoryPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}
/**
* Get the file that the history page is stored in
* or should be stored in.
*
* @param application the application used to access the file.
* @return a valid file object, note that the file might not exist.
*/
@NonNull
private static File getHistoryPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}