1

如何在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()); 
+0

可以共享通知的截图..代码似乎很好..也有没有在logcat的错误? –

+0

logcat不显示任何错误。但状态栏显示一个空白的白色图标来代替应用程序图标 –

+0

@RahilAli。你能开始接受你的问题的答案吗? – petey

回答

6

在android 5.0上,通过使所有不透明像素为白色的颜色过滤器来传递图标。

从,http://developer.android.com/design/patterns/notifications.html

使用颜色来区别于他人您的应用程序。通知图标应该只是透明背景图像。

+0

感谢您的信息..我也没有意识到这一点...... –

+0

是的这是正确的,每个人都想知道为什么在实际通知中有一个彩色图标,而在实际状态栏中只显示一个白色轮廓顶端。 – Danuofr

1
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); 
    }