Get resources from another apk

I have been struggling with this problem all day and have not been successful. I am basically trying to get an image resource from another apk.

So, if com.example.app has an image named image1.png in the res folder, I want com.example2.app to be able to access this resource and put it in the image.

I know you need to use PackageManager.getResourcesForApplication, but I still could not get the actual resource.

Any help would be awesome!

+8
java android eclipse package-managers
source share
2 answers

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 to find out more explanation for another question! Share source resource between apk

+15
source share

try the following:

 final String packName = "com.example.app "; Resources resources; try { PackageManager manager = getPackageManager(); resources = manager.getResourcesForApplication(packName); int resID = resources.getIdentifier("image1", "drawable", packName); Log.d(TAG, "resID = " + resID); Drawable image = getResources().getDrawable(resID); Log.d(TAG, "resID = " + resID); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } 
+4
source share

All Articles