Android interface Notificationmanager use bitmap to make icons _android

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.