Get resources from another apk

前端 未结 2 1789
青春惊慌失措
青春惊慌失措 2020-12-28 21:51

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

相关标签:
2条回答
  • 2020-12-28 22:28

    try this:

    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();
    }
    
    0 讨论(0)
  • 2020-12-28 22:42

    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

    0 讨论(0)
提交回复
热议问题