获取资源从另一个APK [英] Get resources from another apk
问题描述
我一直在努力奋斗着这个问题了一整天,都没有成功。我基本上想从另外一个APK的图像资源。
I have been struggling with this issue all day and have had no success. I am basically trying to get an image resource from another apk.
因此,如果com.example.app有一个名为image1.png在res文件夹中的形象,我想com.example2.app才能够获得该资源,并将其放置在一个ImageView的。
So if com.example.app has an image called image1.png in the res folder, i want com.example2.app to be able to gain access to that resource and place it in an imageview.
我知道,你必须使用PackageManager.getResourcesForApplication,但我仍然没有成功地让实际的资源。
I know you have to use PackageManager.getResourcesForApplication, but i have still been unsuccessful in getting the actual resource.
任何帮助将是真棒!
推荐答案
想通了......
final String packName = "com.example2.app";
String mDrawableName = "app_icon";
try {
PackageManager manager = getPackageManager();
Resources mApk1Resources = manager.getResourcesForApplication(packName);
int mDrawableResID = mApk1Resources.getIdentifier(mDrawableName, "drawable",packName);
Drawable myDrawable = mApk1Resources.getDrawable( mDrawableResID );
if( myDrawable != null )
TEST.setBackgroundDrawable(myDrawable );
}
catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
点击此处查看表格的其他问题更多的解释! APK的之间共享原始资源
Check here for more explanation form other question! Share raw resource between apk's
这篇关于获取资源从另一个APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!