How do I setup an Android Notification Channel?











up vote
0
down vote

favorite












I looked at the example code Android "Create a Notification" example and created my own version of it:



import android.support.v4.app.NotificationCompat;

...

Notification notification = new NotificationCompat.Builder(this, (String) CHANNEL_ID)
.setContentTitle("Eumag")
.setContentText("foreground service running")
.setSmallIcon(R.drawable.ic_android)
.setContentIntent(pendingIntent)
.build();


However, that yielded this error when I tried to build the project:




error: constructor Builder in class Builder cannot be applied to given
types; required: Context found: ForegroundService,String reason:
actual and formal argument lists differ in length




I did some research and found out that it means that there is no constructor that accept the given parameters. So I looked into the NotificationCompat.Builder documents. According to the docs, both of the following methods should exist, but in the source code, only one of them does:



NotificationCompat.Builder(Context context) [Exists]

NotificationCompat.Builder(Context context, String channelId) [Doesn't Exist]



That's fine I guess, so I go try an alternative which is "setChannelId(String channelId)" and that's not in there either! I AM CONFUSION.



build.gradle



android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.eumag"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':spotify-app-remote')
implementation "com.google.code.gson:gson:2.6.1"
implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
implementation 'com.github.spotify:android-auth:9425c6a140'
implementation 'com.github.nkzawa:socket.io-client:0.3.0'
}









share|improve this question
























  • Which version of the support libraries are you using? Note that the two-parameter constructor wasn't added until version 26.1.0.
    – Mike M.
    Nov 21 at 0:56






  • 1




    Possible duplicate of NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification
    – Jantzilla
    Nov 21 at 3:16










  • My build.gradle doesn't look like his though... I'm assuming I need to implement the most recent support library then? If so, how do I go about doing that?
    – Johnny Boy
    Nov 21 at 4:07















up vote
0
down vote

favorite












I looked at the example code Android "Create a Notification" example and created my own version of it:



import android.support.v4.app.NotificationCompat;

...

Notification notification = new NotificationCompat.Builder(this, (String) CHANNEL_ID)
.setContentTitle("Eumag")
.setContentText("foreground service running")
.setSmallIcon(R.drawable.ic_android)
.setContentIntent(pendingIntent)
.build();


However, that yielded this error when I tried to build the project:




error: constructor Builder in class Builder cannot be applied to given
types; required: Context found: ForegroundService,String reason:
actual and formal argument lists differ in length




I did some research and found out that it means that there is no constructor that accept the given parameters. So I looked into the NotificationCompat.Builder documents. According to the docs, both of the following methods should exist, but in the source code, only one of them does:



NotificationCompat.Builder(Context context) [Exists]

NotificationCompat.Builder(Context context, String channelId) [Doesn't Exist]



That's fine I guess, so I go try an alternative which is "setChannelId(String channelId)" and that's not in there either! I AM CONFUSION.



build.gradle



android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.eumag"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':spotify-app-remote')
implementation "com.google.code.gson:gson:2.6.1"
implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
implementation 'com.github.spotify:android-auth:9425c6a140'
implementation 'com.github.nkzawa:socket.io-client:0.3.0'
}









share|improve this question
























  • Which version of the support libraries are you using? Note that the two-parameter constructor wasn't added until version 26.1.0.
    – Mike M.
    Nov 21 at 0:56






  • 1




    Possible duplicate of NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification
    – Jantzilla
    Nov 21 at 3:16










  • My build.gradle doesn't look like his though... I'm assuming I need to implement the most recent support library then? If so, how do I go about doing that?
    – Johnny Boy
    Nov 21 at 4:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I looked at the example code Android "Create a Notification" example and created my own version of it:



import android.support.v4.app.NotificationCompat;

...

Notification notification = new NotificationCompat.Builder(this, (String) CHANNEL_ID)
.setContentTitle("Eumag")
.setContentText("foreground service running")
.setSmallIcon(R.drawable.ic_android)
.setContentIntent(pendingIntent)
.build();


However, that yielded this error when I tried to build the project:




error: constructor Builder in class Builder cannot be applied to given
types; required: Context found: ForegroundService,String reason:
actual and formal argument lists differ in length




I did some research and found out that it means that there is no constructor that accept the given parameters. So I looked into the NotificationCompat.Builder documents. According to the docs, both of the following methods should exist, but in the source code, only one of them does:



NotificationCompat.Builder(Context context) [Exists]

NotificationCompat.Builder(Context context, String channelId) [Doesn't Exist]



That's fine I guess, so I go try an alternative which is "setChannelId(String channelId)" and that's not in there either! I AM CONFUSION.



build.gradle



android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.eumag"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':spotify-app-remote')
implementation "com.google.code.gson:gson:2.6.1"
implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
implementation 'com.github.spotify:android-auth:9425c6a140'
implementation 'com.github.nkzawa:socket.io-client:0.3.0'
}









share|improve this question















I looked at the example code Android "Create a Notification" example and created my own version of it:



import android.support.v4.app.NotificationCompat;

...

Notification notification = new NotificationCompat.Builder(this, (String) CHANNEL_ID)
.setContentTitle("Eumag")
.setContentText("foreground service running")
.setSmallIcon(R.drawable.ic_android)
.setContentIntent(pendingIntent)
.build();


However, that yielded this error when I tried to build the project:




error: constructor Builder in class Builder cannot be applied to given
types; required: Context found: ForegroundService,String reason:
actual and formal argument lists differ in length




I did some research and found out that it means that there is no constructor that accept the given parameters. So I looked into the NotificationCompat.Builder documents. According to the docs, both of the following methods should exist, but in the source code, only one of them does:



NotificationCompat.Builder(Context context) [Exists]

NotificationCompat.Builder(Context context, String channelId) [Doesn't Exist]



That's fine I guess, so I go try an alternative which is "setChannelId(String channelId)" and that's not in there either! I AM CONFUSION.



build.gradle



android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.eumag"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':spotify-app-remote')
implementation "com.google.code.gson:gson:2.6.1"
implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
implementation 'com.github.spotify:android-auth:9425c6a140'
implementation 'com.github.nkzawa:socket.io-client:0.3.0'
}






android service notifications channel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 4:04

























asked Nov 21 at 0:20









Johnny Boy

614




614












  • Which version of the support libraries are you using? Note that the two-parameter constructor wasn't added until version 26.1.0.
    – Mike M.
    Nov 21 at 0:56






  • 1




    Possible duplicate of NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification
    – Jantzilla
    Nov 21 at 3:16










  • My build.gradle doesn't look like his though... I'm assuming I need to implement the most recent support library then? If so, how do I go about doing that?
    – Johnny Boy
    Nov 21 at 4:07


















  • Which version of the support libraries are you using? Note that the two-parameter constructor wasn't added until version 26.1.0.
    – Mike M.
    Nov 21 at 0:56






  • 1




    Possible duplicate of NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification
    – Jantzilla
    Nov 21 at 3:16










  • My build.gradle doesn't look like his though... I'm assuming I need to implement the most recent support library then? If so, how do I go about doing that?
    – Johnny Boy
    Nov 21 at 4:07
















Which version of the support libraries are you using? Note that the two-parameter constructor wasn't added until version 26.1.0.
– Mike M.
Nov 21 at 0:56




Which version of the support libraries are you using? Note that the two-parameter constructor wasn't added until version 26.1.0.
– Mike M.
Nov 21 at 0:56




1




1




Possible duplicate of NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification
– Jantzilla
Nov 21 at 3:16




Possible duplicate of NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification
– Jantzilla
Nov 21 at 3:16












My build.gradle doesn't look like his though... I'm assuming I need to implement the most recent support library then? If so, how do I go about doing that?
– Johnny Boy
Nov 21 at 4:07




My build.gradle doesn't look like his though... I'm assuming I need to implement the most recent support library then? If so, how do I go about doing that?
– Johnny Boy
Nov 21 at 4:07

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403578%2fhow-do-i-setup-an-android-notification-channel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403578%2fhow-do-i-setup-an-android-notification-channel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...