I am trying to send a notification using Notification builder class, but i am getting an error No Channel found.
Here is my code and error
Intent intent = new Intent(MainActivity.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this, "1")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Title")
.setContentText("content")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("Much longer text that cannot fit one line..."))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_DEFAULT;
String description = "description";
CharSequence name = getString(R.string.channel_name);
NotificationChannel channel = new NotificationChannel("1", name, importance);
channel.setDescription(description);
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, builder.build());
Log error
2024-10-26 11:53:01.195 1239-3921 NotificationService system_server E No Channel found for pkg=com.example.myapplication, channelId=1, id=1, tag=null, opPkg=com.example.myapplication, callingUid=10263, userId=0, incomingUserId=0, notificationUid=10263, notification=Notification(channel=1 shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
2024-10-26 11:53:20.069 1239-1396 NotificationService system_server E No Channel found for pkg=com.example.myapplication, channelId=1, id=1, tag=null, opPkg=com.example.myapplication, callingUid=10263, userId=0, incomingUserId=0,
You need to sign in to view this answers