【问题标题】:layout accessed from another APK could'nt access its drawable resources从另一个 APP 访问的布局无法访问其可绘制资源
【发布时间】:2013-04-25 10:11:21
【问题描述】:

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

这是我访问布局的代码

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

【问题讨论】:

  • 我什至尝试删除 gen 和 bin 文件夹来重新创建它,但它从来没有奏效。但如果我复制访问到我的项目的布局的 apk 中使用的所有可绘制资源,则有效。但我不想那样做。希望有人能提供帮助

标签: android performance android-layout android-intent apk


【解决方案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);

【讨论】:

  • 我不想单独访问可绘制图像。我想为布局的 remoteView 充气。因此,在扩展此布局时,我希望我的编译器搜索另一个 APK 的可绘制文件夹,而不是我的。
  • 试试这个示例,mylifewithandroid.blogspot.in/2011/01/… ...尝试在 resPlugin1 包的 aaa.xml 中插入一个 ImageView 看看会发生什么
猜你喜欢
  • 1970-01-01
  • 2016-04-23
  • 1970-01-01
  • 1970-01-01
  • 2013-12-07
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多