通知不会出现在奥利奥下方

时间:2018-04-28 13:30:31

标签: android notifications

在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());

    }
}

}

1 个答案:

答案 0 :(得分:1)

您使用旧版本支持小图标的mipmap,例如尝试使用PNG