【问题标题】:Is it possible to access resources in another APK without using content providers?是否可以在不使用内容提供程序的情况下访问另一个 APK 中的资源?
【发布时间】:2011-01-04 11:22:25
【问题描述】:

我认为除非使用内容提供程序,否则无法访问其他 APK 中包含的资源。但是,我偶然发现了一个名为 Better Keyboard 的应用程序。它使用皮肤,所以我决定下载一个皮肤示例。

An example skin 真的让我很惊讶。它几乎不包含任何代码,只声明一个活动,没有内容提供者。尽管如此,它包含资源,如果安装了带有皮肤的 APK,它们显然可以从 Better Keyboard 应用程序中以某种方式访问​​。那么它是如何实现的呢?

【问题讨论】:

    标签: android android-contentprovider


    【解决方案1】:

    我相信你正在寻找

    Resources res = mPackageManager.getResourcesForApplication("org.example.foo");

    http://developer.android.com/reference/android/content/pm/PackageManager.html#getResourcesForApplication%28java.lang.String%29

    【讨论】:

      【解决方案2】:

      试试这个

       PathClassLoader loader = 
       new PathClassLoader ("/data/app/com.skin.apk", null,PathClassLoader.getSystemClassLoader());
       InputStream f = loader.getResourceAsStream("res/drawable/icon.png");
       Bitmap bitmap=BitmapFactory.decodeStream(f);
       BitmapDrawable b=new BitmapDrawable(bitmap);
       mButton.setBackgroundDrawable(b);
      

      【讨论】:

        【解决方案3】:

        可以通过使用getresoucesforapplication 并且您需要res.getidentifier 来检索资源ID。但是,检索样式资源时似乎不起作用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-07-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-11-05
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多