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);

以上是我构建通知的代码。

您需要设置两个不同的视图,一个是自定义内容视图,另一个是大内容视图,并将其设置为如下 -

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());

还请阅读我有关推送通知的自定义布局的博客

最新更新