是否可以在不使用内容提供程序的情况下访问另一个 APK 中的资源?

发布于 2024-10-10 09:48:32 字数 317 浏览 0 评论 0原文

我认为除非使用内容提供程序,否则不可能访问其他APK中包含的资源。然而,我偶然发现了一个名为“更好的键盘”的应用程序。它使用皮肤,所以我决定下载一个皮肤示例。

示例皮肤着实令我惊讶。它几乎不包含任何代码,仅声明一个活动而没有内容提供者。尽管如此,它仍然包含资源,并且如果安装了带有皮肤的 APK,显然可以通过 Better Keyboard 应用程序访问它们。那么它是如何做到的呢?

I thought that it is impossible to access resources contained in other APK unless content providers are used. However, I stumbled upon an app called Better Keyboard. It uses skins, so I decided to download an example of a skin.

An example skin really surprised me. It contains almost no code, declares only an activity and no content providers. Nontheless it contains resources and they are apparently somehow accessed from Better Keyboard app if the APK with the skin gets installed. So how is it done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巴黎盛开的樱花 2024-10-17 09:48:32

我相信您正在寻找

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

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

I believe you're looking for

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

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

醉生梦死 2024-10-17 09:48:32

试试这个

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

Try this

 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);
毁我热情 2024-10-17 09:48:32

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

It is possible by using getresoucesforapplication and you need res.getidentifier to retrieve the resource Id. However, It seem not work when retrieving style resource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文