1

我有一个显示通知的应用程序我正在许多设备上测试我的应用程序,它运行良好。但是在 OnePlus 上,应用程序的通知会消失,并且在状态栏中不可见。如果手机屏幕打开,我可以看到提示通知,但它不会留在状态栏中。如果手机屏幕关闭,我会听到设备通知声音,但在锁屏或状态栏上没有通知。

这是我使用的代码:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
        .setAutoCancel(true)
                .setSmallIcon(R.drawable.vimi_notification_icon)
                .setLargeIcon(icon)
        .setContentTitle(ctx.getString(R.string.app_name))
        .setLights(Color.argb(255, 0, 207, 255), 750, 2000)         
        .setContentText(content);

        mBuilder.setStyle(inboxStyle);


        if (!TextUtils.isEmpty(Common.getRingtone()) && playSound) {
            if(enoughTimeSinceLastSound) {
                mBuilder.setSound(Uri.parse(Common.getRingtone()));
            }
            playedSound = true;
        }


        int id_to_open = sd.id;
        if(sd.streamId != sd.id) {
            id_to_open = sd.streamId;
        }
        Intent intent = new Intent(ctx, VimiChatterMainActivity.class);
        intent.putExtra(Common.PROFILE_ID, String.valueOf(id_to_open));
        intent.putExtra(Common.CLEAR_NOTIFICATIONS, true);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(pi);

        if(playedSound) {
            lastTimestampOfSoundPlay = System.currentTimeMillis();
        }

        if (Build.VERSION.SDK_INT >= 16) {
            mBuilder.setVibrate(new long[0]);
            mBuilder.setPriority(Notification.PRIORITY_HIGH);
        }
        mNotificationManager.notify(VIMI_NOTIFICATION_ID, mBuilder.build());

我已确保该应用程序有权显示通知并且它在打盹白名单中。我没有想法

4

0 回答 0