如何使用Android的使用通知收件箱风格? [英] How to use Notification Inbox style using android?

查看:183
本文介绍了如何使用Android的使用通知收件箱风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用通知收件箱风格完全吻合。我只是想这低于code和它显示在Notification.InboxStyle错误()。我做了什么错?任何人都可以帮我这个问题?这是我的code ..

I do not know how to use Notification Inbox style exactly. I just tried this below code and it is showing error at Notification.InboxStyle(). What mistake I did? Can anyone help me out with this issue? Here is my code..

  private void generateNotification(Context context, String message) {
    System.out.println(message+"++++++++++2");
    int icon = R.drawable.ic_message;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.message_title);
    String subTitle = context.getString(R.string.message_subtitle);
    Intent notificationIntent = new Intent(context, Output.class);
    notificationIntent.putExtra("content", message);
    PendingIntent intent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    Notification base = new Notification.Builder(context)
    .setTicker(message)
    .setSmallIcon(icon)
    .setWhen(when)
    .setContentTitle(title)
    .setContentText(subTitle)
    .setNumber(4)
    .setContentIntent(intent)
    .build();

    Notification notification = new Notification.InboxStyle(base)
    .addLine("First Message")
    .addLine("Second Message")
    .addLine("Third Message")
    .addLine("Fourth Message")
    .setBigContentTitle("Here Your Messages")
    .setSummaryText("+3 more")
    .build();

    //To play the default sound with your notification:
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);



}

在此先感谢。

Thanks in advance.

推荐答案

的构造函数是

Notification.InboxStyle(Notification.Builder builder)

和你传递一个通知。 像这样,而不是

and you are passing in a Notification. Do like this instead

Notification notification = new Notification.InboxStyle(new Notification.Builder(context)
.setTicker(message)
.setSmallIcon(icon)
.setWhen(when)
.setContentTitle(title)
.setContentText(subTitle)
.setNumber(4)
.setContentIntent(intent))
.addLine("First Message")
.addLine("Second Message")
.addLine("Third Message")
.addLine("Fourth Message")
.setBigContentTitle("Here Your Messages")
.setSummaryText("+3 more")
.build();

这篇关于如何使用Android的使用通知收件箱风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆