簡體   English   中英

在以下oreo的Android版本上無法接收通知

[英]Not able to receive notifications On Android version below oreo

我將Firebase雲功能用於設備到設備的通知,但通知在oreo以下的版本上不起作用。

private void sendNotification1(String notificationTitle, String notificationBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);
    PendingIntent pendingIntent1 = PendingIntent.getBroadcast(this, 0,new Intent(this, MyReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteInput remoteInput = new RemoteInput.Builder(NOTIFICATION_REPLY)
            .setLabel("Respond to Message")
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(android.R.drawable.ic_delete,
                    "Reply Now...", pendingIntent1)
                    .addRemoteInput(remoteInput)
                    .build();

我在這里為奧利奧創建通知渠道

 NotificationChannel notificationChannel = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationChannel = new NotificationChannel(CHANNEL_ONE_ID,
                CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_HIGH );

        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setShowBadge(true);
        notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ONE_ID)
            .setAutoCancel(true)   //Automatically delete the notification
            .setSmallIcon(R.mipmap.ic_launcher)//Notification icon
            .addAction(action)
            .addAction(R.drawable.accept, "ACCEPT", pendingIntent)
            .addAction(R.drawable.delete, "DECLINE", pendingIntent)
            .setContentIntent(pendingIntent)
            .setContentTitle(notificationTitle)
            .setContentText(notificationBody)
            .setSound(defaultSoundUri);


    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationManager.createNotificationChannel(notificationChannel);
    }
    notificationManager.notify(1, notificationBuilder.build());
}

我也提到了清單中的條目。 正確接收到oreo上的通知,但低於oreo版本的通知是不可見的。 請幫幫我。

在Oreo中,通知顯示使用代碼中的chanel ID。 但在oreo版本以下,無需使用chanel ID。

在收到來自friebase的通知時,檢查是否獲取日志。 如果您正在獲取日志,則通知功能正常運行,則表示未正確通知設備。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM