当前位置: 首页>>代码示例>>Java>>正文


Java Context.getClassLoader方法代码示例

本文整理汇总了Java中android.content.Context.getClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getClassLoader方法的具体用法?Java Context.getClassLoader怎么用?Java Context.getClassLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getClassLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchPluginByContext

import android.content.Context; //导入方法依赖的package包/类
private static String fetchPluginByContext(Context c, Uri uri) {
    // 根据Context的ClassLoader来看到底属于哪个插件,还是只是主程序
    ClassLoader cl = c.getClassLoader();
    String pn = PluginFactory.fetchPluginName(cl);
    if (TextUtils.isEmpty(pn)) {
        // 获得了无效的插件信息,这种情况很少见,故打出错误信息,什么也不做
        if (LOGR) {
            LogRelease.e(PLUGIN_TAG, "ppc.fubc: pn is n. u=" + uri);
        }
        return null;
    } else if (TextUtils.equals(pn, RePlugin.PLUGIN_NAME_MAIN)) {
        // 此Context属于主工程,则也什么都不做。稍后会直接走“主程序的Context”来做处理
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "PluginProviderClient.fubc(): Call Main! u=" + uri);
        }
        return null;
    } else {
        // 返回这个Plugin名字
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "PluginProviderClient.fubc(): Call Plugin! u=" + uri);
        }
        return pn;
    }
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:25,代码来源:PluginProviderClient.java

示例2: installNavitveLibraryABI

import android.content.Context; //导入方法依赖的package包/类
/**
 * you can reflect your current abi to classloader library path
 * as you don't need to use load*Library method above
 * @param context
 * @param currentABI
 */
public static void installNavitveLibraryABI(Context context, String currentABI) {
    Tinker tinker = Tinker.with(context);
    if (!tinker.isTinkerLoaded()) {
        TinkerLog.i(TAG, "tinker is not loaded, just return");
        return;
    }
    TinkerLoadResult loadResult = tinker.getTinkerLoadResultIfPresent();
    if (loadResult.libs == null) {
        TinkerLog.i(TAG, "tinker libs is null, just return");
        return;
    }
    File soDir = new File(loadResult.libraryDirectory, "lib/" + currentABI);
    if (!soDir.exists()) {
        TinkerLog.e(TAG, "current libraryABI folder is not exist, path: %s", soDir.getPath());
        return;
    }
    ClassLoader classLoader = context.getClassLoader();
    if (classLoader == null) {
        TinkerLog.e(TAG, "classloader is null");
        return;
    }
    TinkerLog.i(TAG, "before hack classloader:" + classLoader.toString());

    try {
        installNativeLibraryPath(classLoader, soDir);
    } catch (Throwable throwable) {
        TinkerLog.e(TAG, "installNativeLibraryPath fail:" + throwable);
    }
    TinkerLog.i(TAG, "after hack classloader:" + classLoader.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:TinkerLoadLibrary.java

示例3: getComponentNameByContext

import android.content.Context; //导入方法依赖的package包/类
/**
 * 根据Context所带的插件信息,来填充Intent的ComponentName对象
 * 若外界将Context.xxxService方法用PluginServiceClient代替(如编译工具所做的),则这里会做如下事情:
 *      1、将外界传递的Intent为com.qihoo360.mobilesafe的包名,变成一个特定插件的包名
 *      2、这样交给外界的时候,其ComponentName已变成“插件名-类名”的形式,可以做下一步处理
 *      3、若其后处理失败,则仍会调用系统的相应方法(但不是该函数的职责)
 *
 * @param c    根据Context内容来决定如何填充Intent,此为那个Context对象
 * @param from ComponentName
 * @return 新的ComponentName。或者如果插件有问题,则返回from
 */
public static ComponentName getComponentNameByContext(Context c, ComponentName from) {
    if (from == null) {
        // 如果Intent里面没有带ComponentName,则我们不支持此特性,直接返回null
        // 外界会直接调用其系统的对应方法
        return null;
    }
    String appPackage = IPC.getPackageName();
    if (!TextUtils.equals(from.getPackageName(), appPackage)) {
        // 自己已填好了要使用的插件名(作为CN的Key),这里不做处理
        return from;
    }

    // 根据Context的ClassLoader来看到底属于哪个插件,还是只是主程序
    ClassLoader cl = c.getClassLoader();
    String pn = PluginFactory.fetchPluginName(cl);
    if (TextUtils.isEmpty(pn)) {
        // 获得了无效的插件信息,这种情况很少见,故打出错误信息,什么也不做
        if (LOGR) {
            LogRelease.e(PLUGIN_TAG, "pch.iibc: pn is n. n=" + from);
        }
    } else if (TextUtils.equals(pn, RePlugin.PLUGIN_NAME_MAIN)) {
        // 此Context属于主工程,则也什么都不做。稍后会直接走“主程序的Context”来做处理
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "PluginClientHelper.iibc(): Call Main! n=" + from);
        }
    } else {
        // 将Context所在的插件名写入CN中,待后面的方法去处理
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "PluginClientHelper.iibc(): Call Plugin! n=" + from);
        }
        return new ComponentName(pn, from.getClassName());
    }
    return from;
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:46,代码来源:PluginClientHelper.java

示例4: getJarClassLoader

import android.content.Context; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public static JarClassLoader getJarClassLoader(Context context, String jarname, String packagename) {
    String dexInternalPath = JarUtil.getJarInFolderName(context, jarname);
    String optimizedDexOutputPath = JarUtil.getJarOutFolderName(context);
    if (dexLoaders.containsKey(packagename)) {
        return (JarClassLoader) dexLoaders.get(packagename);
    }
    JarClassLoader cl = new JarClassLoader(packagename, dexInternalPath, optimizedDexOutputPath, context.getApplicationInfo().nativeLibraryDir, context.getClassLoader());
    dexLoaders.put(packagename, cl);
    return cl;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:JarLoader.java

示例5: loadClass

import android.content.Context; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public static Class loadClass(Context context, String jarName, String packageName, String className) {
    String dexInternalPath = JarUtil.getJarInFolderName(context, jarName);
    String optimizedDexOutputPath = JarUtil.getJarOutFolderName(context);
    if (!TextUtils.isEmpty(dexInternalPath)) {
        try {
            JarClassLoader cl;
            if (dexLoaders.containsKey(packageName)) {
                cl = (JarClassLoader) dexLoaders.get(packageName);
            } else {
                cl = new JarClassLoader(packageName, dexInternalPath, optimizedDexOutputPath, context.getApplicationInfo().nativeLibraryDir, context.getClassLoader());
                dexLoaders.put(packageName, cl);
            }
            return cl.loadClass(packageName + "." + className);
        } catch (Exception e) {
            JLog.i("clf", "!!!!!!! loadClass--" + packageName + " e is " + e.getMessage());
            return null;
        }
    } else if (mReloadNum >= 1) {
        return null;
    } else {
        mReloadNum++;
        JLog.i("plugin", "JarUtil.updatePlugin 333333333333333333");
        JarUtil.updatePlugin(context, 0, false);
        return loadClass(context, jarName, packageName, className);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:28,代码来源:JarLoader.java

示例6: injectDexElements

import android.content.Context; //导入方法依赖的package包/类
/**
 * 合并注入
 *
 * @param context
 * @param patchFilePath 补丁所在文件夹(尽量是SD卡的路径, 否则会打开文件失败)
 * @throws Exception
 */
public static void injectDexElements(Context context, String patchFilePath) throws Exception {
    ClassLoader pathClassLoader = context.getClassLoader();

    /**dex, 优化后的路径, 必须在要App data目录下, 否则会没有权限*/
    File oDexFile = new File(context.getDir("odex", Context.MODE_PRIVATE).getAbsolutePath());
    /**dex 补丁文件路径(文件夹)*/
    File patchFile = new File(patchFilePath);

    if (!patchFile.exists()) {
        patchFile.mkdirs();
    }

    // 合并成一个数组
    Object applicationDexElement = getDexElementByClassLoader(pathClassLoader);

    for (File dexFile : patchFile.listFiles()) {
        ClassLoader classLoader = new DexClassLoader(dexFile.getAbsolutePath(),// dexPath
                oDexFile.getAbsolutePath(),// optimizedDirectory
                null,
                pathClassLoader
        );
        // 获取这个classLoader中的Element
        Object classElement = getDexElementByClassLoader(classLoader);
        //Log.e("TAG", classElement.toString());
        applicationDexElement = combineArray(classElement, applicationDexElement);
    }

    // 注入到pathClassLoader中
    injectDexElements(pathClassLoader, applicationDexElement);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:38,代码来源:Fix.java

示例7: DexLoader

import android.content.Context; //导入方法依赖的package包/类
public DexLoader(Context var1, String[] var2, String var3, String var4) {
    Object var5 = var1.getClassLoader();
    String var6 = var1.getApplicationInfo().nativeLibraryDir;
    if(!TextUtils.isEmpty(var4)) {
        var6 = var6 + File.pathSeparator + var4;
    }

    for(int var7 = 0; var7 < var2.length; ++var7) {
        var5 = this.mClassLoader = new DexClassLoader(var2[var7], var3, var6, (ClassLoader)var5);
    }

}
 
开发者ID:LightSun,项目名称:android-util2,代码行数:13,代码来源:DexLoader.java

示例8: getProp

import android.content.Context; //导入方法依赖的package包/类
private static final String getProp(Context context, String property) {
	try {
		ClassLoader cl = context.getClassLoader();
		Class<?> SystemProperties = cl.loadClass("android.os.SystemProperties");
		Method method = SystemProperties.getMethod("get", String.class);
		Object[] params = new Object[1];
		params[0] = property;
		return (String)method.invoke(SystemProperties, params);
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:13,代码来源:SysInfoUtil.java

示例9: getServiceComponentFromIntent

import android.content.Context; //导入方法依赖的package包/类
/**
 * 启动 Service 时,从 Intent 中获取 ComponentName
 */
private static ComponentName getServiceComponentFromIntent(Context context, Intent intent) {
    ClassLoader cl = context.getClassLoader();
    String plugin = PluginFactory.fetchPluginName(cl);

    /* Intent 中已指定 ComponentName */
    if (intent.getComponent() != null) {
        // 根据 Context 所带的插件信息,来填充 Intent 的 ComponentName 对象。具体见方法说明
        return PluginClientHelper.getComponentNameByContext(context, intent.getComponent());

    } else {
        /* Intent 中已指定 Action,根据 action 解析出 ServiceInfo */
        if (!TextUtils.isEmpty(intent.getAction())) {
            ComponentList componentList = PluginFactory.queryPluginComponentList(plugin);
            if (componentList != null) {
                // 返回 ServiceInfo 和 Service 所在的插件
                Pair<ServiceInfo, String> pair = componentList.getServiceAndPluginByIntent(context, intent);
                if (pair != null) {
                    return new ComponentName(pair.second, pair.first.name);
                }
            }
        } else {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "PSS.startService(): No Component and no Action");
            }
        }
    }
    return null;
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:32,代码来源:PluginServiceClient.java

示例10: getProp

import android.content.Context; //导入方法依赖的package包/类
public static String getProp(Context context, String property) {
 	try {
 		ClassLoader cl = context.getClassLoader();
 		@SuppressWarnings("rawtypes")
Class SystemProperties = cl.loadClass("android.os.SystemProperties");
 		@SuppressWarnings("unchecked")
Method method = SystemProperties.getMethod("get", String.class);
 		Object[] params = new Object[1];
 		params[0] = new String(property);
 		return (String)method.invoke(SystemProperties, params);
 	} catch (Exception e) {
 		return null;
 	}
 }
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:15,代码来源:WelcomeAty.java

示例11: createClassLoader

import android.content.Context; //导入方法依赖的package包/类
public ClassLoader createClassLoader() throws TGResourceException {
	Context context = this.activity.getApplicationContext();
	
	String optimizedDirectory = context.getDir("dex", Context.MODE_PRIVATE).getAbsolutePath();
	
	List<String> fileNames = this.unpackPlugins(optimizedDirectory);
	if(!fileNames.isEmpty()) {
		return new DexClassLoader(this.createPath(fileNames), optimizedDirectory, this.createLibraryPath(), context.getClassLoader());
	}
	return null;
}
 
开发者ID:axlecho,项目名称:tuxguitar,代码行数:12,代码来源:TGResourceLoaderImpl.java

示例12: LoadApplication

import android.content.Context; //导入方法依赖的package包/类
public static void LoadApplication (Context context, ApplicationInfo runtimePackage, String[] apks)
{
	synchronized (lock) {
		if (context instanceof android.app.Application) {
			Context = context;
		}
		if (!initialized) {
			android.content.IntentFilter timezoneChangedFilter  = new android.content.IntentFilter (
					android.content.Intent.ACTION_TIMEZONE_CHANGED
			);
			context.registerReceiver (new mono.android.app.NotifyTimeZoneChanges (), timezoneChangedFilter);
			
			System.loadLibrary("monodroid");
			Locale locale       = Locale.getDefault ();
			String language     = locale.getLanguage () + "-" + locale.getCountry ();
			String filesDir     = context.getFilesDir ().getAbsolutePath ();
			String cacheDir     = context.getCacheDir ().getAbsolutePath ();
			String dataDir      = getNativeLibraryPath (context);
			ClassLoader loader  = context.getClassLoader ();

			Runtime.init (
					language,
					apks,
					getNativeLibraryPath (runtimePackage),
					new String[]{
						filesDir,
						cacheDir,
						dataDir,
					},
					loader,
					new java.io.File (
						android.os.Environment.getExternalStorageDirectory (),
						"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath (),
					MonoPackageManager_Resources.Assemblies,
					context.getPackageName ());
			
			mono.android.app.ApplicationRegistration.registerApplications ();
			
			initialized = true;
		}
	}
}
 
开发者ID:KilianCorbel,项目名称:timeout,代码行数:43,代码来源:MonoPackageManager.java

示例13: getClassLoader

import android.content.Context; //导入方法依赖的package包/类
public ClassLoader getClassLoader(ApplicationInfo appInfo) {
    Context context = createPackageContext(appInfo.packageName);
    return context.getClassLoader();
}
 
开发者ID:codehz,项目名称:container,代码行数:5,代码来源:VClientImpl.java

示例14: loadClassList

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取所有类
 * @param context 上下文
 * @param pkgName 指定要获取类所在的包名
 * @param baseClass 指定要获取类所实现的基类
 */
public static List<Class> loadClassList(@NonNull Context context, String pkgName, @Nullable Class baseClass) {
    List<Class> classList = new ArrayList<>();

    Context appContext = context.getApplicationContext();
    ClassLoader classLoader = appContext.getClassLoader();

    String entry = "";
    try {
        Field pathListField = findField(classLoader, "pathList");
        Object dexPathList = pathListField.get(classLoader);

        Field dexElementsField = findField(dexPathList, "dexElements");
        Object[] dexElements = (Object[]) dexElementsField.get(dexPathList);
        for (Object dexElement : dexElements) {
            Field dexFileField = findField(dexElement, "dexFile");
            DexFile dexFile = (DexFile) dexFileField.get(dexElement);

            Enumeration<String> entries = dexFile.entries();
            while (entries.hasMoreElements()) {
                entry = entries.nextElement();
                if (entry.startsWith("com.android") || entry.startsWith("android")) {
                    // 忽略 android 包名下的类
                    continue;
                } else if (entry.contains("$")) {
                    // 忽略内部类
                    continue;
                }

                if (entry.contains(pkgName)) {
                    Class<?> clazz = dexFile.loadClass(entry, classLoader);
                    if (clazz == null || clazz.isInterface()) {
                        // 忽略接口
                        continue;
                    }

                    if (baseClass != null) {
                        if (baseClass.isAssignableFrom(clazz)) {
                            classList.add(clazz);
                        }
                    } else {
                        classList.add(clazz);
                    }
                }
            }
        }
    } catch (Exception | Error e) {
        Log.e(TAG, "reflect fail. class = " + entry + " Exception: " + e.getMessage());
    }

    return classList;
}
 
开发者ID:JeremyHe-cn,项目名称:Mvp,代码行数:58,代码来源:ReflectUtils.java

示例15: getClassLoader

import android.content.Context; //导入方法依赖的package包/类
/**
 * Get package class loader
 *
 * @param context current locatorContext
 * @param pkgName package name
 * @return package class loader
 * @throws NameNotFoundException name not found exception
 */
static ClassLoader getClassLoader(@NonNull final Context context, final String pkgName) throws NameNotFoundException
{
	final Context providerContext = context.createPackageContext(pkgName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
	return providerContext.getClassLoader();
}
 
开发者ID:1313ou,项目名称:Treebolic,代码行数:14,代码来源:Utils.java


注:本文中的android.content.Context.getClassLoader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。