Is it possible to access resources in another APK without using content providers?
Asked Answered
E

3

17

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?

Elianaelianora answered 4/1, 2011 at 11:22 Comment(0)
E
21

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

Easiness answered 5/1, 2011 at 5:14 Comment(0)
J
3

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);
Jammie answered 4/1, 2011 at 11:33 Comment(0)
M
0

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.

Myrtie answered 1/11, 2011 at 2:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.