Integrate images into Android jar

Android jar is special. In case of general jar. You can copy images into jar file.
And, we can read from jar file.
But, Android.., we cannot read image directly. Because Android has their own rule to read.

Instead of this, we read image from binary or base64 string. It is easy!
Jar file should be included only source codes.

Many people provide conversion tool as web tool. is one of
You can search by “base64”, “image”.

You can get base64 style string from this kind of tool.
You copy this data in your code directly.


How to create BitmapDrawable

public class RewardBitmapFactory {

  public static BitmapDrawable getDrawable(String code, Context context) {
    DisplayMetrics localDisplayMetrics = context.getResources()
    byte[] arrayOfByte = Base64.decode(code, 0);
    BitmapDrawable drawable = ((BitmapDrawable) BitmapDrawable
        .createFromStream(new ByteArrayInputStream(arrayOfByte), null));
    drawable.setTargetDensity(getDencity(localDisplayMetrics.xdpi, context));
    return drawable;

  public static int getDencity(float paramFloat, Context paramContext) {
    return (int) (getDim(paramFloat, paramContext) + 0.5F);

  public static float getDim(float paramFloat, Context paramContext) {
    DisplayMetrics localDisplayMetrics = paramContext.getResources()
    return TypedValue.applyDimension(1, paramFloat, localDisplayMetrics);