Can't get the NotificationCompat.Builder 2 arg Constructor

Viewed 1372

i am trying to build a Notification with Target API 26 and min API 19. I can't get the NotificationCompat.Builder Constructor which takes the Channel ID as a 2nd argument.

This is my Notification Class so far. At the very bottom i want to get the Notification 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");
}

}

1 Answers

You should set google support libs to 26.1.0 or higher and check your build.gradle. It should be like:

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

android {
//...
}
Related