0

i want when user clicks the button a notification is shown in top of phone , here is my code what i have done

My logcat

E/NotificationService: No Channel found for pkg=com.example.imageslider, channelId=null, id=0, tag=null, opPkg=com.example.imageslider, callingUid=10286, userId=0, incomingUserId=0, notificationUid=10286, notification=Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)

My java code on click method

 NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_baseline_account_box_24
            )
            .setContentTitle("This is the test notification")
            .setContentText("test notifications ");


    Intent  notificationIntent = new Intent(this,MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(contentIntent);

    NotificationManager  notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0,builder.build());

1 Answers1

1

From Android 8.0 if you want to show a notification, you should associate it to a Notification Channel.

First you should create a new notification Channel then show your notification.

You can find more detailed information here: https://developer.android.com/training/notify-user/channels

Jorge Martinez
  • 176
  • 1
  • 2