How can I get the ID of an icon of another application?
<p>I need to create home shortcuts of other applications. in order to do that I need to get the ID of the icon drawable.</p>

<p>I can get the actual drawable, but i dont know how to get the ID of it without knowing the name of the drawabale.</p>

<p>Is there a way to find the name of the drawable or get the ID from the drawable object?</p>

<p>i think i said drawable too many times.</p>

<pre><code>//get icon drwable
public Drawable getIcon(String pack) {
        final PackageManager pm = context.getPackageManager();
        try {
            return pm.getApplicationIcon(pack);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

public void makeShortcut(String pack){
         Intent shortcutIntent;

            shortcutIntent = new Intent();
            shortcutIntent.setComponent(new ComponentName(pack, ".classname"));
            int iconId =geIconId(pack); // a default icon for now TODO


            Log.i("icon id", ""+iconId);
            shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            final Intent putShortCutIntent = new Intent();
            putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
                    shortcutIntent);

            // Sets the custom shortcut's title
            putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,  getAppName(pack));
            putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(
                    context,iconId));
            putShortCutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            context.sendBroadcast(putShortCutIntent);
    }
</code></pre>
