从另一个APK访问的布局无法访问其可绘制资源
问题描述:
我通过访问其服务中的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);
答
这位朋友你好,请试试这个。
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);
我甚至尝试删除gen和bin文件夹来重新创建它,但它从来没有工作。但如果我复制所有可访问到我的项目的布局的apk中使用的可绘制资源的作品。但我不想这样做。有人可以帮助 – jaagstorm 2013-04-25 10:19:23