更新通知而不使用Collasping通知抽屉

时间:2015-08-18 12:59:07

标签: android

我有一个通知管理器,可以在点击时启动活动。

mBuilder =
           new NotificationCompat.Builder(context)
               .setSmallIcon(R.drawable.ic_launcher)
               .setOngoing(true)
               .setOnlyAlertOnce(true)
               .setPriority(NotificationCompat.PRIORITY_MAX)
               .setContent(remoteViews)
               .setAutoCancel(false);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, Launch.class).putExtra("type", 0), 0);
mBuilder.setContentIntent(pendingIntent);

在此执行的功能也可以是异步的,具体取决于用户的偏好。我想将通知更新为持续进展。这种性质的东西:

 mBuilder =
            new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setOngoing(true)
                .setContentTitle("Sending details")
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setProgress(100, 0, true)
                .setOnlyAlertOnce(true)
                .setAutoCancel(false);

选择通知时。这是实现的,但我想要做的是更新从前者到后者的通知,而不必首先向上滑动导航抽屉。

1 个答案:

答案 0 :(得分:0)

试试这个..

    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);  
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());  

您需要 NOTIFICATION_ID 来更新特定通知。

请参阅JSFiddle