【问题标题】:Way to Accessing Resources and Resource Ids of other Apps访问其他应用程序的资源和资源 ID 的方法
【发布时间】:2013-11-26 07:39:22
【问题描述】:

经过一些研究和实践,我观察到我们可以使用PackageManagerlike访问其他应用程序的资源

Resources resources = getApplicationContext().getPackageManager().getResourcesForApplication(appPackageName);

但仅仅访问Resources 是不够的。我们需要为每个 Resource 组件(如 Drawable、布局、字符串等)提供 Id,以便从 Resources 中访问它们。

我在 SO 中进行了搜索,并为如何获取其他应用程序的资源 ID 而苦苦挣扎,但没有得到正确的解决方案。我在SO中看到,有人建议使用

之类的方法
resources.getIdentifier(String name, String defType, String defPackage);
resources.getValue(String name, TypedValue outValue, boolean resolveRefs);
resources.getValue(int id, TypedValue outValue, boolean resolveRefs);

但不知道如何使用它们。

我需要访问其他应用程序的资源(绘图、字符串、布局...)。

帮我解决这个问题。任何帮助将不胜感激...

谢谢大家 对不起我的英语......

【问题讨论】:

  • 如果发生这种情况,将是严重的安全漏洞。
  • @AbhishekV 因为我们能够获取资源,我希望我们能够获取资源组件,例如 Drawables、布局等……不是吗?
  • @GopalRao Ya 我们可以获取资源。但是要从 Resources 对象中获取可绘制对象,我们需要知道该可绘制对象的名称/ID。只有当我们是这两个应用程序的开发者时,我们才会知道它。
  • 您是否要访问任何未知应用程序或您已开发的应用程序的资源?
  • @GrIsHu 任何其他应用程序的资源。它们可能由我或其他人开发......

标签: android android-resources


【解决方案1】:

感谢您的提问, 我可以通过以下代码访问。它工作正常..

String lAppPkg = "com.example.sharedlogos";
resources = getApplicationContext().getPackageManager()
                            .getResourcesForApplication(lAppPkg);
int lID = resources.getIdentifier( mID, "drawable",
                            lAppPkg);
mImage.setBackground(resources.getDrawable(lID));

【讨论】:

    【解决方案2】:

    我没有时间完美地完成,但这应该可以:

    https://github.com/alt236/Android-Drawables---Android

    该项目尝试至少从其他应用程序获取所有可绘制对象。这也可以在 Google Play 上找到:Android Resource Viewer

    【讨论】:

    • 但他们清楚地提到了This application will list all public and private Android resources (i.e. resources located under 'android.R.*' and under 'com.android.internal.R.*') for the current device....而不是其他应用程序的资源...
    猜你喜欢
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    相关资源
    最近更新 更多