通知未在API26的锁屏上显示

时间:2018-12-07 09:25:46

标签: android

这是我的通知代码。我已经尝试过NotificationCompat.VISIBILITY_PUBLICpublic void createNotification(String title,String body) { String name = "my_package_channel"; String id = "my_package_channel_1"; // The user-visible name of the channel. String description = "my_package_first_channel"; // The user-visible description of the channel. Intent intent; PendingIntent pendingIntent; NotificationCompat.Builder builder; if (Build.VERSION.SDK_INT >=26) { int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = notifManager.getNotificationChannel(id); if (mChannel == null) { mChannel = new NotificationChannel(id, name, importance); mChannel.setDescription(description); mChannel.setLightColor(Color.GREEN); mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC); notifManager.createNotificationChannel(mChannel); } builder = new NotificationCompat.Builder(this, id); intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); builder.setContentTitle(title) // required .setSmallIcon(R.drawable.sslogo) // required .setContentText(body)//(this.getString(R.string.app_name)) // required .setDefaults(Notification.DEFAULT_ALL) .setContentIntent(pendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); } else { builder = new NotificationCompat.Builder(this); intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); builder.setContentTitle(title) .setSmallIcon(R.drawable.sslogo) // required .setContentText(body) // required .setDefaults(Notification.DEFAULT_ALL) .setContentIntent(pendingIntent) .setPriority(Notification.PRIORITY_HIGH); } Notification notification = builder.build(); notifManager.notify(NOTIFY_ID, notification); } 但是锁屏上没有任何反应。尽管在应用程序设置中,我允许锁定屏幕显示。

{{1}}

0 个答案:

没有答案