Android-Skin-Loader
Android-Skin-Loader copied to clipboard
6.0系统,无法更新插件皮肤
在6.0 系统上,无法更新皮肤功能,定位到代码是因为 对 sdcard读取权限的问题
@Override
protected Resources doInBackground(String... params) {
try {
if (params.length == 1) {
String skinPkgPath = params[0];
File file = new File(skinPkgPath);
if(file == null || !file.exists()){
return null;
}
PackageManager mPm = context.getPackageManager();
PackageInfo mInfo = mPm.getPackageArchiveInfo(skinPkgPath, PackageManager.GET_ACTIVITIES);
skinPackageName = mInfo.packageName;
AssetManager assetManager = AssetManager.class.newInstance();
Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class);
addAssetPath.invoke(assetManager, skinPkgPath);
Resources superRes = context.getResources();
Resources skinResource = new Resources(assetManager,superRes.getDisplayMetrics(),superRes.getConfiguration());
SkinConfig.saveSkinPath(context, skinPkgPath);
skinPath = skinPkgPath;
isDefaultSkin = false;
return skinResource;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
};
代码L160,获取的mInfo == null。
检查权限,检查skin资源包路径,把skin资源放在手机内部sdcard文件夹下,不要放在扩展的sdcard中.
对,android4.4以后就不允许在外部SD卡读写了