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

后端 未结 3 1588
难免孤独
难免孤独 2020-12-13 00:49

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

相关标签:
3条回答
  • 2020-12-13 01:28

    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);
    
    0 讨论(0)
  • 2020-12-13 01:48

    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

    0 讨论(0)
  • 2020-12-13 01:49

    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.

    0 讨论(0)
提交回复
热议问题