下面介绍的是动态加载未安装的apk.然后读取apk中图片,显示在宿主app中
1.首先准备换肤的apk
skindemo-debug.apk
skindemo2-debug.apk
这2个apk中都有一张图片,然后我们push这两个apk到sdcard中就可以
资源加载问题,怎么通过Resources 加载另外一个apk中的图片
/**
* 获取AssetManager 用来加载插件资源
*
* @param pFilePath 插件的路径
* @return
*/
private AssetManager createAssetManager(String pFilePath) {
try {
final AssetManager assetManager = AssetManager.class.newInstance();
final Class> assetManagerClazz = Class.forName(“android.content.res.AssetManager”);
final Method addAssetPathMethod = assetManagerClazz.getDeclaredMethod(“addAssetPath”, String.class);
addAssetPathMethod.setAccessible(true);
addAssetPathMethod.invoke(assetManager, pFilePath);
return assetManager;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//这个Resources就可以加载非宿主apk中的资源
private Resources createResources(String pFilePath) {
final AssetManager assetManager = createAssetManager(pFilePath);
Resources superRes = this.getResources();
return new Resources(assetManager, superRes.getDisplayMetrics(), superRes.getConfiguration());
}
3.宿主apk,动态换肤的点击事件代码
private boolean mChange = false;
private String skinType = “”;
private int APK_TYPE;