通知出现在通知列表中,但不会在主屏幕上弹出

什雷亚斯帕特内

我正在分享两张图片,请看一下你会明白我的问题

在第一张图像通知中成功显示更好的我的通知,但我希望它首先出现在主屏幕上,如第二张图像所示,只是这个电报通知。

     public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        //        r.play();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            r.setLooping(false);
        }

        // vibration
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        long[] pattern = {100, 300, 300, 300};
        v.vibrate(pattern, -1);

         int resourceImage = getResources().getIdentifier(remoteMessage.getNotification().getIcon(), "drawable", getPackageName());

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "CHANNEL_ID");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setSmallIcon(R.mipmap.betterme);
        } else {
            builder.setSmallIcon(R.mipmap.betterme);
        }
        Intent resultIntent = new Intent(this, SplashScreen.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setContentTitle(remoteMessage.getNotification().getTitle());
        builder.setContentText(remoteMessage.getNotification().getBody());
        builder.setContentIntent(pendingIntent);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody()));
        builder.setAutoCancel(true);
        builder.setOngoing(true);
        builder.setPriority(NotificationCompat.PRIORITY_MAX);
        builder.setSound(notification);

        mNotificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            String channelId = "Your_channel_id";
            NotificationChannel channel = new NotificationChannel(
                    channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_HIGH);
            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build();
            channel.setSound(notification, audioAttributes);
            mNotificationManager.createNotificationChannel(channel);
            builder.setChannelId(channelId);
        }
        mNotificationManager.notify(100, builder.build());
    }
}

第一张图片

第二张图片

佩什基拉

如果我理解正确,您希望收到提醒通知。

请注意,android 系统决定何时将通知设为提醒通知并拥有最终决定权 - 而不是开发者您。在这里你可以找到一些例子:https : //developer.android.com/guide/topics/ui/notifiers/notifications#Heads-up

确保您的设置反映了这些。从您的示例来看,情况似乎是这样,但也许您已经更改了通知渠道设置(从应用程序设置),这会覆盖您的代码首选项(用户优先于应用程序)。

此外,请注意,如果您向上(而不是侧向)滑动抬头通知,Android 会开始一段冷静时间,在几秒钟(或更长时间)内不会出现来自该应用的抬头通知。您也可以尝试使用 Telegram 或任何其他应用程序。在冷静时间过后,它会像提醒通知一样再次出现。这是 Android 用来防止应用对用户造成困扰的一种方式。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通知出现在“错误”屏幕上

可以观察到的变化,但不会在敲门通知中通知订户

使用PushPlugin插件,Phonegap推送通知不会出现在状态栏或iOS的锁定屏幕中

Firebase 通知在后台运行,但不会出现在 Oreo 的前台中

在主屏幕上弹出

Android-GCM推送通知未出现在通知列表中

通知未出现在通知托盘中

javascript 警报不会在 php echo 上弹出

过去的通知出现在现在

吐司通知没有出现在MVC 4中

FCM通知未出现在iOS Flutter中

通知按钮未出现在iOS 10中

Android 通知未出现在 BroadcastReceiver 中

通知未出现在notify()上

Android Studio:“应用程序”图标未出现在主屏幕或应用程序列表中

引导多选全选不会出现在列表中

幽灵用户?用户既不会出现在登录屏幕上,也不会出现在“用户”命令中

通知发送通知出现在窗口下方

发生本地通知但未出现在屏幕上

共享javascript sdk不会在IE7和IE8上弹出

iOS Widget 不会在主屏幕中第一次读取 UserDeafults 值

列表项不会出现在屏幕上,而是打印在控制台上

离子4弹出窗口出现在屏幕外

页脚出现在较小的屏幕中

Android:防止应用程序在后台时在屏幕上弹出数据通知

电池电量不足通知不会在Windows 7中显示

点击应用程序图标不会在应用程序中显示通知

通知有时不会在使用 RxAndroidBle 的 notify/write observable 中调用

单击通知不会在后台打开活动