androidandroid-launcher

Using icon packs in my app


My app includes a feature for listing all apps installed on the user's device, complete with icons. Now users request icon pack support in this list.

At the moment I list installed apps with:

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

final List<ResolveInfo> rgRi = pm.queryIntentActivities( mainIntent, 0);

and then load icons for each ResolveInfo with:

.loadIcon(application.getPackageManager());

This gives me the app's icon but not the icon pack one but the default one.

How do I access the icon pack icon for an app if one is available?


Solution

  • Answering my own question. Here is a short tutorial (complete with pseudo-code) on loading icons from icon packs.

    Get installed icon packs

    Find apps with intent filter com.gau.go.launcherex.theme or org.adw.launcher.THEMES. Possibly others exist too. Use e.g.

    PackageManager.queryIntentActivities(new Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA);
    

    Load appfilter.xml

    It can be found as a resource or in the assets folder of the icon pack. Use either

    int i = Resources.getIdentifier("appfilter", "xml", "iconpack.package.name");
    Resources.getXml(i);
    

    or

    InputStream s = iconPackres.getAssets().open("appfilter.xml");
    XmlPullParserFactory f = XmlPullParserFactory.newInstance();
    f.setNamespaceAware(true);
    XmlPullParser p = f.newPullParser();
    p.setInput(s, "utf-8");
    

    Parse appfilter.xml

    Appfilter.xml describes the icon pack content. Among other things the themer has the ability to draw icons on backgrounds, provide masks etc. This is all described on XDA: http://forum.xda-developers.com/showthread.php?t=1649891 . What we are most interested in is the <item> tags e.g.

    <item component="ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}" drawable="com_android_browser_browseractivity" />
    

    The component attribute contains the name of the package and activity and the drawable is the name of the matching icon within the icon pack. Loop through the XmlPullParser from previous step to find the icon you want.

    Load icon

    Simply get the component name for the app whose icon you want to load with

    PackageManager.getLaunchIntentForPackage("app.package.name").getComponent().toString();
    

    Than load icon with

    Resources.getIdentifier(componentName, "drawable", "app.package.name"); 
    Resources.getDrawable(...)