簡體   English   中英

是否可以在不使用內容提供商的情況下訪問另一個APK中的資源?

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

我認為除非使用內容提供商,否則無法訪問其他APK中包含的資源。 但是,我偶然發現了一個名為Better Keyboard的應用程序。 它使用皮膚,所以我決定下載一個皮膚的例子。

皮膚的一個例子讓我感到驚訝。 它幾乎不包含任何代碼,僅聲明活動而不包含內容提供者。 盡管如此,它包含資源,如果安裝了帶皮膚的APK,它們顯然可以通過Better Keyboard應用程序進行訪問。 那怎么辦?

我相信你在找

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

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

試試這個

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

通過使用getresoucesforapplication可以使用res.getidentifier來檢索資源ID。 但是,在檢索樣式資源時似乎不起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM