0

I am trying to display android notification, Struggling a lot to display android notification. Please help me, Not sure whats going wrong with this.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int notifyID = 1;
        String CHANNEL_ID = "my_channel_01";// The id of the channel.
        CharSequence name = "Testing";// The user-visible name of the channel.
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
        Notification notification = new Notification.Builder(MainActivity.this)
            .setContentTitle("New Message")
            .setContentText("You've received new messages.")
            .setSmallIcon(R.drawable.ic_launcher_foreground)
            .setChannelId(CHANNEL_ID)
            .build();
    }}
daedsidog
  • 1,637
  • 2
  • 10
  • 33
  • You have to create the `NotificationChannel` first: https://stackoverflow.com/a/44534559. – Mike M. Dec 16 '18 at 08:46
  • Also, I just noticed that that answer doesn't explicitly state so, but you need to use the regular `NotificationManager` for the `createNotificationChannel()` call, not `NotificationManagerCompat`, which doesn't have that method. – Mike M. Dec 16 '18 at 09:00
  • You didn't have to change the code you had already. You just needed to add the the `NotificationChannel` creation: https://drive.google.com/file/d/1Dk0g5Vt-SRFSN-VoJFv8rmw26czZsQGg/view?usp=drivesdk. – Mike M. Dec 16 '18 at 09:14

0 Answers0