Today, I saw EoE question and answer there is this "[Android interface]notificationmanager How to use bitmap to do the icon" such a problem, in the forum search there is no good case
Feature a simple demo for everyone to refer to
Today, Notificationmanager is using bitmap to make icons.
Key Code
Copy Code code as follows:
public void notification (int flag)
{
Notification Notification = new Notification ();
Set icon for StatusBar display
Notification.icon = R.drawable.icon;
Set the text information displayed by StatusBar
Mynoti.tickertext= new_msg;
Notification.flags = Notification.flag_auto_cancel;
Set the default sound when notification occurs
Notification.defaults = Notification.default_sound;
Remoteviews Contentview = new Remoteviews (Getpackagename (), r.layout.custom_notification);
Bitmap Bitmap=null;
if (flag==0)
{
Bitmap=drawabletobitmap (This.getresources (). getdrawable (R.drawable.icon));
}else
{
Here is the key place, you can get the picture from the network or sdcard, turn into bitmap can
Bitmap=drawabletobitmap (This.getresources (). getdrawable (R.drawable.alert_dialog_icon));
}
Contentview.setimageviewbitmap (R.id.notification_icon, bitmap);
Contentview.settextviewtext (R.id.app_name, "Custom notification");
Notification.contentview = Contentview;
Intent Intent = new Intent (this, mainactivity.class);
Pendingintent contentintent = pendingintent.getactivity (this, 0, intent,
Pendingintent.flag_update_current);
Notification.contentintent = contentintent;
Show notification
Random Random = new Random (new Date (). GetTime ());
Mnotificationmanager.notify (Random.nextint (1000000), notification);
}
Transformation Drawabletobitmap
public static Bitmap Drawabletobitmap (drawable drawable)
{
Bitmap Bitmap = Bitmap.createbitmap (Drawable.getintrinsicwidth (), Drawable.getintrinsicheight (), Drawable.getopacity ()!= pixelformat.opaque? Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565);
Canvas Canvas = new Canvas (bitmap);
Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());
Drawable.draw (canvas);
return bitmap;
}
SOURCE Download: Notificationicon.rar