簡體   English   中英

從另一個APK獲取資源

[英]Get resources from another apk

我整天都在為這個問題而苦苦掙扎,但沒有成功。 我基本上是試圖從另一個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();
        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之間共享原始資源

嘗試這個:

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM