2013-04-25 108 views
1

我通過訪問其服務中的applicationInfo並通過packageManager獲取資源,從而訪問了另一個APK的佈局。如果在佈局中只指定了textView和Buttons,那麼它工作正常。但如果在訪問的佈局中使用任何可繪製資源,則拋出Resource not found Exception從另一個APK訪問的佈局無法訪問其可繪製資源

這是我的代碼來訪問佈局

ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0); 
Resources res = packageManager.getResourcesForApplication(info); 
XmlResourceParser xres = res.getLayout(0x7f030000); 
+0

我甚至嘗試刪除gen和bin文件夾來重新創建它,但它從來沒有工作。但如果我複製所有可訪問到我的項目的佈局的apk中使用的可繪製資源的作品。但我不想這樣做。有人可以幫助 – jaagstorm 2013-04-25 10:19:23

回答

1

這位朋友你好,請試試這個。

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); 
+0

我不想單獨訪問可繪製的圖像。我想膨脹佈局的remoteView。因此,在擴充此佈局時,我希望我的編譯器搜索其他APK的可繪製文件夾,而不是我的。 – fuzionpro 2013-04-25 11:36:11

+0

嘗試此示例,http://mylifewithandroid.blogspot.in/2011/01/plugins-with-user-interface.html ...嘗試在resPlugin1包的aaa.xml中插入ImageView並查看會發生什麼 – jaagstorm 2013-04-25 11:47:57