Android 通知适用于使用 android 11 的 AVD,但不适用于使用 android 10 的真实设备。以下是我的代码

我使用 FCM 发送通知,下面是我在 onmessageReceive firebase 方法的 on received 部分调用的代码。困扰我的部分是通知在我运行 android 11 的 AVD 中运行良好,但在我的三星 Galaxy J6+ 设备上没有显示。请帮忙!

private void createNormalNotificationChatRequest(String meetingType)
{
    Uri uri = RingtoneManager.getDefaulturi(RingtoneManager.TYPE_RINGTONE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"Incoming Call");
    builder.setContentTitle("New Chat Request")
            .setContentText("Open Nhare and respond")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setautoCancel(true)
            .setColor(ResourcesCompat.getcolor(getResources(),R.color.colorHighlighterDark,null))
            .setsound(uri);

    Intent intent = new Intent(getapplicationContext(),FeedFragment.class);
    PendingIntent pendingIntent = PendingIntent.getactivity(this,intent,PendingIntent.flaG_UPDATE_CURRENT);

    builder.setContentIntent(pendingIntent);

    Notificationmanager manager = (Notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(new Random().nextInt(85-65),builder.build());
}

@RequiresApi(api = Build.VERSION_CODES.O)
private void createOreonormalNotificationChatRequest(String meetingType)
{
    NotificationChannel channel = new NotificationChannel("Chat Requests","Chat Requests",Notificationmanager.IMPORTANCE_HIGH);
    channel.setShowBadge(true);
    channel.enableLights(true);
    channel.enableVibration(true);
    channel.setDescription("Chat Requests");
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);

    Notificationmanager manager = (Notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.createNotificationChannel(channel);

    Intent intent = new Intent(this,FeedFragment.class);

    PendingIntent pendingIntent = PendingIntent.getactivity(this,PendingIntent.flaG_UPDATE_CURRENT);

    Notification notification = new Notification.Builder(this,Constants.REMOTE_MSG_INVITER_TOKEN)
            .setContentTitle("New Chat Request")
            .setContentText("Open Nhare and Respond")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setautoCancel(true)
            .setContentIntent(pendingIntent)
            .setColor(ResourcesCompat.getcolor(getResources(),R.color.colorWhiteHundred,null))
            .build();

    manager.notify(new Random().nextInt(85-65),notification);
}
zhen521314 回答:Android 通知适用于使用 android 11 的 AVD,但不适用于使用 android 10 的真实设备。以下是我的代码

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/42566.html

大家都在问