从另一个apk获取资源 [英] Get resources from another apk
问题描述
所以如果com.example.app在res文件夹中有一个名为image1.png的图像,我想要com .example2.app能够访问该资源并将其放在imageview中。
我知道你必须使用PackageManager.getResourcesForApplication,但我还是没有成功获得实际资源。
任何帮助都会很棒!
想出来...
final String packName =com.example2.app;
String mDrawableName =app_icon;
try {
PackageManager manager = getPackageManager();
资源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自动生成的catch块
e.printStackTrace();
}
查看更多说明形成其他问题! 在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.
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.
I know you have to use PackageManager.getResourcesForApplication, but i have still been unsuccessful in getting the actual resource.
Any help would be awesome!
Figured it out...
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();
}
Check here for more explanation form other question! Share raw resource between apk's
这篇关于从另一个apk获取资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!