NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) 无法处理 Oreo Firebase 通知

NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) not working on Oreo Firebase notification

我正在尝试使用 Oreo 版本 中的 Firebase 显示通知,所以当我获得解决方案时它没有显示
NotificationCompat.Builder(this, CHANNEL_ID) 但我看到的是这样

我的 build.gradle 文件是

    apply plugin: 'com.android.application'

    dependencies {
    compile project(':library')
    compile project(':camerafragment')
    compile 'com.google.android.gms:play-services:11.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.17'
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
    compile 'com.google.firebase:firebase-messaging:11.0.0'
    compile 'com.google.android.gms:play-services-maps:11.0.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.android.support:design:26.0.0-alpha1'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.google.android.gms:play-services-auth:11.0.0'
    compile 'net.gotev:uploadservice:2.1'
    compile 'com.google.firebase:firebase-auth:11.0.0'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.android.support:support-v4:26.0.0-alpha1'
    }

    android {

    compileSdkVersion 27
    buildToolsVersion "27.0.0"
    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        applicationId "com.trashmap"
        minSdkVersion 17
        targetSdkVersion 27

        // Enabling multidex support.
        multiDexEnabled true
        versionCode 17
        versionName "1.16"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
           // shrinkResources true//new add to reduce size
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }



      sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

apply plugin: 'com.google.gms.google-services'
NotificationCompat.Builder (Context context)

This constructor was deprecated in API level 26.1.0.

use NotificationCompat.Builder(Context, String) instead. All posted Notifications must specify a NotificationChannel Id.

并且你已经定义了compile 'com.android.support:support-v4:26.0.0-alpha1'所以你必须更改你的支持库的版本号。

文档中提到构建器方法 NotificationCompat.Builder(Context context) 已被弃用。我们必须使用具有 channelId 参数的构造函数:

NotificationCompat.Builder(上下文上下文, String channelId) https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

此构造函数已在 API 级别 26.0.0-beta1 中弃用。使用 NotificationCompat.Builder(Context, String) 代替。所有发布的通知都必须指定一个 NotificationChannel Id。 https://developer.android.com/reference/android/app/Notification.Builder.html

此构造函数已在 API 级别 26 中弃用。请改用 Notification.Builder(Context, String)。所有发布的通知都必须指定一个 NotificationChannel Id。 如果您想重复使用构建器设置器,您可以使用 channelId 创建构建器,并将该构建器传递给辅助方法并在该方法中设置您的首选设置。

试试这个,希望它能奏效...

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext(), "CHANNEL_ID");

        notificationBuilder.setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ic_launcher)
                .setTicker("Dilip21")
                .setContentTitle("Default notification")
                .setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
                .setContentInfo("Info");

NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());