Today, we can see the question "How icationicationmanager uses Bitmap for icons on the [Android interface]" in the eoe q & A. There are no good cases for searching in the Forum.
Close up a simple demo for your reference
Today, icationicationmanager uses Bitmap as an icon.
Key code Copy codeThe Code is as follows: public void notification (int flag)
{
Notification notification = new Notification ();
// Set the icon displayed in statusbar
Notification. icon = R. drawable. icon;
// Set the text 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
{
// This is the key. You can obtain images from the network or sdcard and convert them to bitmap.
Bitmap = drawableToBitmap (this. getResources (). getDrawable (R. drawable. alert_dialog_icon ));
}
ContentView. setImageViewBitmap (R. id. icationication_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;
// Display Notification
Random random = new Random (new Date (). getTime ());
MNotificationManager. Y (random. nextInt (1000000), notification );
}
// Convert 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;
}
Download the source code: icationicationicon.rar