有什么办法获取联系人应用程序的图标?

时间:2012-10-23 13:37:15

标签: java android icons contacts

在android roms之间,联系人应用程序的徽标可能不同(例如,三星设备的联系人图标与HTC设备不同)。有没有办法以编程方式获取此图标?

1 个答案:

答案 0 :(得分:2)

private Drawable getIconFromPackageName(final String packageName) {
        PackageManager packageManager = getPackageManager();
        try {
            Drawable icon = packageManager.getApplicationIcon(packageName);
            return icon;
        } catch (NameNotFoundException e) {
            Toast toast = Toast.makeText(this, "error in getting icon", Toast.LENGTH_SHORT);
            toast.show();
            e.printStackTrace();
        }
        return null;
}

这将返回带有指定包名称图标的Drawable对象(如果存在),否则为null