[英]Push Notification Icon Android
如何在Android的通知区域添加通知图标? 我尝试这样做,但这在通知区域显示空白。
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, Receive_Message_list.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setSmallIcon(R.drawable.pushicon)
.setContentTitle("MAY-I")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notification_message))
.setContentText(notification_message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
在android 5.0上,图标通过彩色滤镜传递,该滤镜使所有非透明像素变为白色。
来自http://developer.android.com/design/patterns/notifications.html
使用颜色将您的应用与其他应用区分开。 通知图标只能是透明的白色背景图像。
private void showNotification(final String title, String text, int ID, boolean showTimeStamp) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) //Use a builder
.setContentTitle(title) // Title
.setContentText(text) // Message to display
.setTicker(text).setSmallIcon(R.drawable.ic_notif_small) // This one is also displayed in ticker message
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bulb)); // In notification bar
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
//mBuilder.addAction(R.drawable.bulb_small, "OK", resultPendingIntent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS | Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
long time = 0;
if (showTimeStamp)
Calendar.getInstance().getTimeInMillis();
else
time = android.os.Build.VERSION.SDK_INT >= 9 ? -Long.MAX_VALUE : Long.MAX_VALUE;
notification.when = time;
//notification.icon = R.drawable.ic_moneta_logo_small;
//mNotificationManager.cancelAll(); //Clear all currently display notifications
mNotificationManager.cancel(ID);
mNotificationManager.notify(ID, notification);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.