devesh kumawat
devesh kumawat

Reputation: 61

NotificationCompact.Builder doesn't accept channel id

I'm trying to create a notification in my app, but the method below doesn't accept the channel id with context. It only accepts the context, so I'm not getting a notification. Please tell me how I can fix this.

NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID).

This is my build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "com.example.murarilal.atry"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding{
    enabled true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == 'com.android.support') {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion '25.3.1'
                }
            }
        }
    }
    //compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile 'com.android.support:design:26.0.0-alpha1'
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.android.support:support-v4:26.0.0-alpha1'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.miguelcatalan:materialsearchview:1.4.0'
}

Upvotes: 0

Views: 266

Answers (1)

Palak Darji
Palak Darji

Reputation: 1114

Make sure you import right version of NotificationCompat

import android.support.v4.app.NotificationCompat;

make sure you have API set to 26.

compileSdkVersion 26
buildToolsVersion "26.0.2"
targetSdkVersion 26

Now, this code should work. It must look for correct constructor

NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"default");

Upvotes: 1

Related Questions