【问题标题】:Notifications not showing on lock screen通知未显示在锁定屏幕上
【发布时间】:2019-08-02 19:05:23
【问题描述】:

我想在锁定屏幕上显示通知,但我无法让它工作。

这是我的代码;

                  .setSmallIcon(R.drawable.deleteaccounticon)
                  .setContentTitle("My notification")
                  .setContentText("Much longer text that cannot fit one line...")
                  .setStyle(new NotificationCompat.BigTextStyle()
                          .bigText("Much longer text that cannot fit one line..."))
                  .setPriority(NotificationCompat.PRIORITY_HIGH);

          builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
              CharSequence name = "channel1";
              String description = "test";
              int importance = NotificationManager.IMPORTANCE_HIGH;
              NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
              channel.setDescription(description);
              // Register the channel with the system; you can't change the importance
              // or other notification behaviors after this


              NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
              notificationManager.createNotificationChannel(channel);
              notificationManager.notify(1,builder.build());
              channel.setLockscreenVisibility(VISIBILITY_PUBLIC);
      } 

通知未显示在锁定屏幕上。该应用的设置允许在锁定屏幕上显示通知。

有什么建议吗?

【问题讨论】:

  • 设置中是否启用了在锁屏中显示通知???

标签: java android android-notifications lockscreen


【解决方案1】:

builder.setOngoing(true)

使通知显示在锁定屏幕上。

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多