简体   繁体   English

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

[英]Is it possible to access resources in another APK without using content providers?

I thought that it is impossible to access resources contained in other APK unless content providers are used. 我认为除非使用内容提供商,否则无法访问其他APK中包含的资源。 However, I stumbled upon an app called Better Keyboard. 但是,我偶然发现了一个名为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. 尽管如此,它包含资源,如果安装了带皮肤的APK,它们显然可以通过Better Keyboard应用程序进行访问。 So how is it done? 那怎么办?

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

It is possible by using getresoucesforapplication and you need res.getidentifier to retrieve the resource Id. 通过使用getresoucesforapplication可以使用res.getidentifier来检索资源ID。 However, It seem not work when retrieving style resource. 但是,在检索样式资源时似乎不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM