I am trying to show notification using Firebase
in Oreo version so it's not showing when I get SolutionNotificationCompat.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'
This method is deprecated. use Builder(Context, String) instead. All posted notifications must specify a NotificationChannel ID.
MainActivity. In this class, clicking the button calls the addNotification() method where we implement the NotificationCompat. Builder object to set the notification properties. The NotificationManager. notify() method is used to display the notification.
It is mentioned in the documentation that the builder method NotificationCompat.Builder(Context context) has been deprecated. And we have to use the constructor which has the channelId parameter:
NotificationCompat.Builder(Context context, String channelId) https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html
This constructor was deprecated in API level 26.0.0-beta1. use NotificationCompat.Builder(Context, String) instead. All posted Notifications must specify a NotificationChannel Id. https://developer.android.com/reference/android/app/Notification.Builder.html
This constructor was deprecated in API level 26. use Notification.Builder(Context, String) instead. All posted Notifications must specify a NotificationChannel Id. If you want to reuse the builder setters, you can create the builder with the channelId, and pass that builder to a helper method and set your preferred settings in that method.
Try this one hope so it will be working...
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());
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With