抬起头推送通知不是做流行起来的功能(Heads up push notification not d

2019-10-30 08:46发布

我是新来的Android和我一直在努力表现出抬起头动作推送通知,就像WhatsApp的一样。

这是我为我的通知配置:

NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, ADMIN_CHANNEL)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_foreground))
                        .setSmallIcon(R.drawable.m_icon)
                        .setContentTitle(remoteMessage.getNotification().getTitle())
                        .setTicker(remoteMessage.getNotification().getBody())
                        .setColor(ContextCompat.getColor(getApplicationContext(), R.color.mblue))
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(remoteMessage.getNotification().getBody()))
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                        .setContentIntent(likePendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0,notificationBuilder.build());

我曾经在一些后阅读的关键acomplish这是高优先级设置为通知,但它仍然不是为我工作。

Answer 1:

问题是,我们要添加一个新的通道配置,只要操作系统是Oroe。 所以我不得不来验证,如果操作系统是奥利奥,然后ASIGN通道到我的notificationManager:

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

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    setupChannels();
}

@RequiresApi(api = Build.VERSION_CODES.O)
private void setupChannels(){
    CharSequence adminChannelName ="Global channel";
    String adminChannelDescription = "Notifications sent from the app admin";
    NotificationChannel adminChannel;
    adminChannel = new NotificationChannel(ADMIN_CHANNEL_ID, adminChannelName, NotificationManager.IMPORTANCE_HIGH);
    adminChannel.setDescription(adminChannelDescription);
    adminChannel.enableLights(true);
    adminChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
    adminChannel.setLightColor(Color.RED);
    adminChannel.enableVibration(true);
    if (notificationManager != null) {
        notificationManager.createNotificationChannel(adminChannel);
    }

}


Answer 2:

对于安卓派(9)在模拟器上,我安装我的“IMPORTANCE_HIGH”通道,并设置我的建设者优先“PRIORITY_HIGH”。

但是,我仍然无法得到单挑通知!

最后,在Android模拟器9,我必须:

  1. 向下滑动通知栏
  2. 点击“管理通知”
  3. 选择我的应用程序
  4. 选择我的频道
  5. 选择“行为”
  6. 使“让声音和弹出屏幕上”。

现在,它的工作原理。



文章来源: Heads up push notification not doing the Pop up function