get Launcher Icon - Android App

Android examples for App:APK Information

Description

get Launcher Icon

Demo Code


//package com.java2s;

import android.content.Context;

import android.content.pm.PackageManager;

import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.service.notification.StatusBarNotification;

public class Main {
    public static Bitmap getLauncherIcon(Context context,
            StatusBarNotification sbn) {
        try {/*from   w w  w  .  j  a  va  2  s  .c o m*/
            String packageName = sbn.getPackageName();
            PackageManager packageManager = context.getPackageManager();
            Drawable iconDrawable = packageManager
                    .getApplicationIcon(packageName);
            if (iconDrawable instanceof BitmapDrawable) {
                BitmapDrawable bitmapDrawable = (BitmapDrawable) iconDrawable;
                return bitmapDrawable.getBitmap();
            }
        } catch (Exception ignored) {
        }
        return null;
    }
}

Related Tutorials