我的应用程序包含一项功能,用于列出用户设备上安装的所有应用程序,并附带图标。现在,用户在此列表中请求图标包支持。
目前,我列出已安装的应用:
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> rgRi = pm.queryIntentActivities( mainIntent, 0);
然后为每个ResolveInfo
加载图标:
.loadIcon(application.getPackageManager());
这为我提供了应用程序的图标,但不是图标包,而是默认图标。
如果应用程序可用,如何访问应用程序的图标包图标?
答案 0 :(得分:12)
回答我自己的问题。以下是从图标包加载图标的简短教程(包含伪代码)。
使用意图过滤器com.gau.go.launcherex.theme
或org.adw.launcher.THEMES
查找应用。其他人也可能存在。
使用例如
PackageManager.queryIntentActivities(new Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA);
可以将其作为资源或图标包的assets文件夹中找到。使用
int i = Resources.getIdentifier("appfilter", "xml", "iconpack.package.name");
Resources.getXml(i);
或
InputStream s = iconPackres.getAssets().open("appfilter.xml");
XmlPullParserFactory f = XmlPullParserFactory.newInstance();
f.setNamespaceAware(true);
XmlPullParser p = f.newPullParser();
p.setInput(s, "utf-8");
Appfilter.xml
描述了图标包内容。除此之外,themer还能够在背景上绘制图标,提供面具等。这些都在XDA上进行了描述:http://forum.xda-developers.com/showthread.php?t=1649891。我们最感兴趣的是<item>
标签,例如
<item component="ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}" drawable="com_android_browser_browseractivity" />
component
属性包含包和活动的名称,drawable
是图标包中匹配图标的名称。循环浏览上一步的XmlPullParser
以找到所需的图标。
只需获取要加载其图标的应用的组件名称
PackageManager.getLaunchIntentForPackage("app.package.name").getComponent().toString();
使用
加载图标Resources.getIdentifier(componentName, "drawable", "app.package.name");
Resources.getDrawable(...)