MarvyP
MarvyP

Reputation: 21

NotificationCompat.Builder does not accept channel id as an argument

I am attempting to set up notifications in my android app, but NotificationCompat will not accept the channel id as an argument. In my gradle file I have

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-compat:27.1.1'

I have also created the channels in my Starter code as below.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(
            CHANNEL_1, "Channel 1", NotificationManager.IMPORTANCE_LOW);

        channel.setDescription("This is channel 1");

        NotificationManager manager = getSystemService(NotificationManager.class);
        if (manager != null) 
            manager.createNotificationChannel(channel);
    }

Finally, I have in the activity code.

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    Notification notification = new NotificationCompat.Builder(this, CHANNEL_1)

......and that is where I find my issue. Android Studio is telling me that the signature block is incorrect. It is not accepting the channel id as a second argument. I have imported both v4, and v7 for the NotificationCompat and neither works. I have also tried

    NotificationCompat.Builder mBuilder = //continued code

I have used the below Android links, and I have not found a solution.

https://developer.android.com/training/notify-user/channels

https://developer.android.com/training/notify-user/build-notification#java

I also have viewed two StackOverflow post, which are below, and still no solution for my case.

NotificationCompat.Builder() not accepting Channel Id as argument

NotificationCompat.Builder doesn't accept 2nd argument

I cannot figure out why this issue is present.

Upvotes: 1

Views: 1301

Answers (1)

MarvyP
MarvyP

Reputation: 21

Well, I found the answer in this article.

How to make it work NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);

    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.0'
            }
        }
    }

Upvotes: 1

Related Questions