Android多图片样式通知与多行摘要文本

时间:2015-01-20 11:11:12

标签: android notifications

我正在尝试使用标有红色的多个行摘要文本创建大图片通知,如下图所示

enter image description here

我已经制作了大图片通知,但我的摘要文字并没有多行,而是单行并且从最后剪切。如果有人知道,请指导。

  

代码

    NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);

    String title = context.getString(R.string.app_name);

    Bitmap remotePicture = null;
    Bitmap appIcon = null;

    // Create the style object with BigPictureStyle subclass.
    NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
    notiStyle.setBigContentTitle(title);
    notiStyle.setSummaryText(message);

    try {
        appIcon = BitmapFactory.decodeResource(context.getResources(), icon);
        remotePicture = BitmapFactory.decodeStream((InputStream) new URL(image).getContent());
    } catch (IOException e) {
        e.printStackTrace();
    }
 // Add the big picture to the style.
    if(remotePicture != null)
        notiStyle.bigPicture(remotePicture);

        // This ensures that the back button follows the recommended convention for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    // Adds the back stack for the Intent (but not the Intent itself).
    try {
        if(in.getData() == null)
            stackBuilder.addParentStack(Class.forName(in.getComponent().getClassName()));
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(in);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification noti = new NotificationCompat.Builder(context)
    .setSmallIcon(icon)
    .setAutoCancel(true)
    .setLargeIcon(appIcon)
    .setContentIntent(resultPendingIntent)
    .setContentTitle(title)
    .setContentText(message)
    .setStyle(remotePicture == null ? null : notiStyle).build();

    noti.defaults |= Notification.DEFAULT_LIGHTS;
    noti.defaults |= Notification.DEFAULT_VIBRATE;
    noti.defaults |= Notification.DEFAULT_SOUND;

    noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;

    notificationManager.notify(0, noti);

0 个答案:

没有答案