Не удается получить конструктор NotificationCompat.Builder 2 arg

я пытаюсь создать уведомление с целевым API 26 и минимальным API 19. Я не могу получить конструктор NotificationCompat.Builder, который принимает идентификатор канала в качестве второго аргумента.

Пока это мой класс уведомлений. В самом низу я хочу получить построитель уведомлений.

public class NotificationHelper extends ContextWrapper {
private NotificationManager notificationManager;

public NotificationHelper(Context base) {
    super(base);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createChannel();
    }
}

@TargetApi(Build.VERSION_CODES.O)
public void createChannel() {
    NotificationChannel channel1 = new NotificationChannel("channel1", "Channel one", NotificationManager.IMPORTANCE_DEFAULT);
    channel1.enableLights(true);
    channel1.enableVibration(true);
    channel1.setLightColor(R.color.colorPrimary);
    channel1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);

    getManager().createNotificationChannel(channel1);
}

public NotificationManager getManager() {
    if (notificationManager == null) {
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }
    return notificationManager;
}

public NotificationCompat.Builder() {
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(getApplicationContext(), "channel1");
}

}


person Florian Walther    schedule 04.10.2017    source источник
comment
Разместите здесь свой build.gradle файл, пожалуйста.   -  person Giorgio Antonioli    schedule 04.10.2017
comment
Я пытаюсь, но он не форматируется должным образом. Что мы ищем?   -  person Florian Walther    schedule 04.10.2017
comment
Вы должны установить библиотеки поддержки на 26.+, чтобы иметь новый конструктор.   -  person Giorgio Antonioli    schedule 04.10.2017
comment
Спасибо, это было на 26.0.0-alpha1, но 26.0.1 сделал свое дело   -  person Florian Walther    schedule 04.10.2017


Ответы (1)


Вы должны установить библиотеки поддержки Google на 26.1.0 или выше и проверить свой build.gradle. Это должно быть так:

apply plugin: 'com.android.application'
//...
repositories {
    maven { url 'https://maven.google.com' }
//..
}

android {
//...
}
person Dima Kozhevin    schedule 04.10.2017
comment
Спасибо. Я просто хочу отметить, что 26.0.1 тоже работает. - person Florian Walther; 05.10.2017