0

I've seen in the Android documentation and other sites (including this one) that it's possible to create a channel and use NotificationCompat but I'm not getting it. I'm about to go crazy trying to make this work.

Using android.support.v7.app.NotificationCompat or android.support.v4.app.NotificationCompat Android Studio show: "Builder(Context) in Builder cannot be applied to (Context, String)"

notificationBuilder = new NotificationCompat.Builder(this, idNoti);// here

It does not even show me a deprecation message of NotificationCompat if I only use Builder(Context).

My build.gradle file:

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 26
        ...
    }
    ...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:26.0.0-alpha1'
    ...
}

I'm using the latest version of Android Studio (2.3.3) on a Mac. I need to use NotificationCompat.

Arnaldo
  • 673
  • 6
  • 22
  • Check out this : https://github.com/googlesamples/android-NotificationChannels/ – Haresh Chhelana Sep 08 '17 at 05:19
  • `26.0.0-alpha1` *is* old - you should be on `26.0.2` at this point. You shouldn't be using `android.support.v7.app.NotificationCompat` at all - it has been deprecated. – ianhanniballake Sep 08 '17 at 05:21
  • @ianhanniballake And how am I supposed to do that? I see everything updated from the sdk manager /: – Arnaldo Sep 08 '17 at 05:29
  • @ianhanniballake Even on windows with the latest version of Android studio. I have everything updated. – Arnaldo Sep 08 '17 at 05:42
  • @user5195185 - they aren't in the SDK Manager anymore: https://developer.android.com/studio/build/dependencies.html#google-maven – ianhanniballake Sep 08 '17 at 05:46
  • @ianhanniballake Nothing changed /: I can only use 26.0.0-alpha1. Why? – Arnaldo Sep 08 '17 at 06:13
  • you need to add repositories { maven { url 'https://maven.google.com' // Alternative URL is 'https://dl.google.com/dl/android/maven2/' } } take a look https://developer.android.com/studio/build/dependencies.html#google-maven – humazed Sep 08 '17 at 06:17
  • @humazed Yes, I did. – Arnaldo Sep 08 '17 at 06:20
  • @ianhanniballake but maybe I need to uninstall support repository from the SDK Manager to make this work? – Arnaldo Sep 08 '17 at 06:20
  • no, you don't, what exactly is the problem, you don't need to update the support lib for notification to work – humazed Sep 08 '17 at 06:34
  • Got it! (uninstalling the support repository from the SDK Manager) – Arnaldo Sep 08 '17 at 07:02
  • https://stackoverflow.com/questions/43093260/notification-not-showing-in-android-8-oreo – amorenew Oct 09 '17 at 06:54

1 Answers1

-1

you need first to create a channel from this answer

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

      /* Create or update. */ 
      NotificationChannel channel = new NotificationChannel("my_channel_01",
          "Channel human readable title",  
          NotificationManager.IMPORTANCE_DEFAULT);
      mNotificationManager.createNotificationChannel(channel);
  } 

and then hook your notification to it.

notificationBuilder = new NotificationCompat.Builder(this, "my_channel_01");

for more info see this video from Android Developers

humazed
  • 74,687
  • 32
  • 99
  • 138