我通过从其服务访问applicationInfo并通过packageManager获取资源来访问另一个APK的布局。如果在布局中仅指定textView和Button,则它可以正常工作。但是如果所访问的布局中使用了任何可绘制资源,则抛出Resource not found Exception

这是我访问布局的代码

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

最佳答案

您好朋友,请尝试此。

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

10-06 03:42