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

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


private static boolean isAppCachePath(Context context, String fullPath) {
    File externalCacheDir = context.getExternalCacheDir();
    if (externalCacheDir != null) {
        if (fullPath.contains(externalCacheDir.getAbsolutePath())) {
            return true;
        }
    }
    File cacheDir = context.getCacheDir();
    if (fullPath.contains(cacheDir.getAbsolutePath())) {
        return true;
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        File codeCacheDir = context.getCodeCacheDir();
        if (fullPath.contains(codeCacheDir.getAbsolutePath())) {
            return true;
        }
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        File dataDir = context.getDataDir();
        if (fullPath.contains(dataDir.getAbsolutePath())) {
            return true;
        }
    }
    File filesDir = context.getFilesDir();
    if (fullPath.contains(filesDir.getAbsolutePath())) {
        return true;
    }
    return false;
}
 

public static DexClassLoader fromBytes(Context context, final byte[] dexBytes) throws Exception {

        if (null == context) {
            throw new RuntimeException("No context provided");
        }

        final String dexFileName = "internal.dex";

        final File dexInternalStoragePath = new File(context.getDir("dex", Context.MODE_PRIVATE), dexFileName);

        if (!dexInternalStoragePath.exists()) {

            prepareDex(dexBytes, dexInternalStoragePath);
        }

        final File optimizedDexOutputPath = context.getCodeCacheDir();

        DexClassLoader loader = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
                optimizedDexOutputPath.getAbsolutePath(), null, context.getClassLoader().getParent());

        dexInternalStoragePath.delete();
        return loader;
    }
 

public static DexClassLoader fromBytes(Context context, final byte[] dexBytes) throws Exception {

        if (null == context) {
            throw new RuntimeException("No context provided");
        }

        String dexFileName = "internal.dex";

        final File dexInternalStoragePath = new File(context.getDir("dex", Context.MODE_PRIVATE), dexFileName);

        if (!dexInternalStoragePath.exists()) {

            prepareDex(dexBytes, dexInternalStoragePath);
        }

        final File optimizedDexOutputPath = context.getCodeCacheDir();

        DexClassLoader loader = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
                optimizedDexOutputPath.getAbsolutePath(), null, context.getClassLoader().getParent());

        dexInternalStoragePath.delete();

        return loader;
    }
 

public static File getCodeCacheDir(Context context) {
    return context.getCodeCacheDir();
}
 
 方法所在类
 同类方法