推送通知图标Android

时间:2015-04-22 14:01:01

标签: android notifications push-notification android-notifications

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

2 个答案:

答案 0 :(得分:6)

在android 5.0上,图标通过一个彩色滤镜传递,使所有非透明像素为白色。

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

  

使用颜色区分您的应用与其他应用。通知图标应该只是透明的白色背景图像。

答案 1 :(得分: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);
    }