我已将Remoteview应用于通知。它在用户处于前台时起作用,但当用户在后台时,通知不会显示为remoteview。
如果用户是后台,我该如何应用remoteview?
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.doggy_downgrade3)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setContentTitle("Doggy")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setNumber(1)
.setPriority(Notification.PRIORITY_MAX)
.setContent(remoteViews)
.setContentIntent(pendingIntent);
以上是我建立通知的代码。
答案 0 :(得分:0)
您需要设置两个不同的视图,一个是自定义内容视图,另一个是大内容视图,并将其设置如下 -
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(icon)
.setCustomContentView(contentViewSmall)
.setCustomBigContentView(contentViewBig)
.setContentTitle("Custom Notification")
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setWhen(when);
mNotificationManager.notify(1, notificationBuilder.build());
上的博客