我正在尝试在 Oreo 版本 中使用 Firebase
显示通知,所以当我得到解决方案时它没有显示NotificationCompat.Builder(this, CHANNEL_ID)
但它向我展示了这样
而我的 build.gradle
文件是
应用插件:'com.android.application'依赖{编译项目(':库')编译项目(':camerafragment')编译'com.google.android.gms:play-services:11.0.0'编译'com.squareup.picasso:picasso:2.5.2'编译'com.mcxiaoke.volley:library:1.0.17'编译'com.android.support:appcompat-v7:26.0.0-alpha1'编译'com.android.support.constraint:constraint-layout:1.0.2'编译'com.android.support:recyclerview-v7:26.0.0-alpha1'编译'com.android.support:cardview-v7:26.0.0-alpha1'编译'com.google.firebase:firebase-messaging:11.0.0'编译'com.google.android.gms:play-services-maps:11.0.0'编译'com.facebook.android:facebook-android-sdk:[4,5)'编译'com.android.support:design:26.0.0-alpha1'编译'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'编译'com.jakewharton:butterknife:7.0.1'编译'com.google.android.gms:play-services-auth:11.0.0'编译'net.gotev:uploadservice:2.1'编译'com.google.firebase:firebase-auth:11.0.0'编译'com.google.code.gson:gson:2.8.0'编译'com.android.support:support-v4:26.0.0-alpha1'}安卓 {compileSdkVersion 27构建工具版本27.0.0"dex 选项 {javaMaxHeapSize "4g"}默认配置 {应用程序IDcom.trashmap"minSdkVersion 17targetSdkVersion 27//启用多索引支持.multiDexEnabled 真版本代码 17版本名称1.16"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型 {发布 {缩小启用假//shrinkResources true//新添加以减小大小proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}源集{主要的 {manifest.srcFile 'AndroidManifest.xml'java.srcDirs = ['src']res.srcDirs = ['res']}}}应用插件:'com.google.gms.google-services'
NotificationCompat.Builder(上下文上下文)
<块引用>
此构造函数在 API 级别 26.1.0 中已弃用.
使用 NotificationCompat.Builder(Context, String)
代替.所有发布的通知都必须指定一个 NotificationChannel Id.
而且你已经定义了 compile 'com.android.support:support-v4:26.0.0-alpha1'
所以你必须改变你的支持库的版本号.
I am trying to show notification using Firebase
in Oreo version so it's not showing when I get Solution
NotificationCompat.Builder(this, CHANNEL_ID)
but it's showing me like this
and my build.gradle
file is
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.
And you have defined compile 'com.android.support:support-v4:26.0.0-alpha1'
So you have to change your version number of support library.
这篇关于NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) 不适用于 Oreo Firebase 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!