在带有7.0版的测试设备上,通知不会出现。虚拟测试运行良好。
我认为代码handels oreo和较低,我错了吗?
public static String channelAufgabeID = "channelTaskID";
public static String channelNameAufgabe = "Task";
@Override
public void onReceive(Context context, Intent intent) {
if (Main.notificationsActive == true) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channelTask = new NotificationChannel(channelTaskID, channelNameTask, NotificationManager.IMPORTANCE_HIGH);
channelTask.enableLights(true);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channelTask);
}
}
Intent repeatingIntent = new Intent(context, Main.class);
repeatingIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, repeatingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setContentTitle("YourWeek")
.setContentIntent(pendingIntent)
.setSmallIcon(R.mipmap.icon_status_bar_deiwo)
.setContentText("You planned a task")
.setChannelId(channelTaskID)
.setAutoCancel(true);
notificationManager.notify(1, builder.build());
}
}
}
您使用的是小图标的mipmap不支持旧版本,请尝试使用png,例如