3

Between android roms the contacts app's logo can be different (e.g. Samsung devices have different contacts icon than HTC devices). Is there any way to programmatically get this icon?

Mark Buikema
  • 2,483
  • 30
  • 53

1 Answers1

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

This will return a Drawable object with the specified package name's icon if it exists, null otherwise.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195