Java 安卓提醒通知未显示
我无法找到我在构建通知时出错的地方 当手机处于活动状态且 当手机处于睡眠状态时,锁定屏幕 这是我尝试过的代码。但却无法取得结果Java 安卓提醒通知未显示,java,android,notifications,Java,Android,Notifications,我无法找到我在构建通知时出错的地方 当手机处于活动状态且 当手机处于睡眠状态时,锁定屏幕 这是我尝试过的代码。但却无法取得结果 PendingIntent pendingIntent = PendingIntent.getActivity(context,0, openIntent,PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(con
PendingIntent pendingIntent = PendingIntent.getActivity(context,0, openIntent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "Normal")
.setSmallIcon(R.drawable.ic_folder)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setVibrate(new long[] {1000})
.setContentTitle(mainListItem.getTitle())
.setContentText(mainListItem.getDetail())
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,builder.build());
回答太晚了… 看起来你的代码对我来说很好,但由于某些原因,这会阻止你的提示出现
回答太晚了… 看起来你的代码对我来说很好,但由于某些原因,这会阻止你的提示出现
您使用的目标sdk、编译和最低sdk版本是什么?Min sdk 14、目标和编译sdk 26这是版本26中的问题,您需要创建一个通知通道来显示通知。有关更多信息,请查看我在android 6.0.1 Marshmallow上运行此应用程序的链接尝试创建通知通道,并查看您使用的目标sdk、编译和最低sdk版本是什么?Min sdk 14、目标和编译sdk 26这是版本26中的问题。您需要创建通知通道来显示通知。有关更多信息,请查看我在android 6.0.1 Marshmallow上运行此应用的链接尝试创建通知通道,并查看以下内容:如果应用的目标版本为26或更高版本,您只需为其创建通知通道:当您的目标版本为安卓8.0(API级别26)时,您必须实现一个或多个通知通道。如果您的targetSdkVersion设置为25或更低,当您的应用程序在Android 8.0(API级别26)或更高版本上运行时,它的行为与在运行Android 7.1(API级别25)或更低版本的设备上的行为相同。为了跟进,您只需要为您的应用程序创建一个通知频道,如果它针对的是26或更高版本:当您针对Android 8.0时(API级别26),您必须实现一个或多个通知通道。如果您的targetSdkVersion设置为25或更低,则当您的应用程序在Android 8.0(API级别26)或更高版本上运行时,其行为与在运行Android 7.1(API级别25)或更低版本的设备上的行为相同。