By Sabyasachi Sahu

2020-06-30 03:21:18 8 Comments

I am trying to create a push notification for my new app. I tried creating the push notification but it is not showing up. I followed the documentation here:

public class MainActivity extends AppCompatActivity {

int notificationID = 1;
String CHANNEL_ID = "food";

private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.channel_name);
        String description = getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
        NotificationManager notificationManager = getSystemService(NotificationManager.class);

protected void onCreate(Bundle savedInstanceState) {

    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder builder= new NotificationCompat.Builder(this, "food")
            .setContentText("What are you doing?")
            .setStyle(new NotificationCompat.BigTextStyle().bigText("What are you doing?"))

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);




The resource string XML code where I have defined the data is here:

    <string name="app_name">Notifications demo</string>
    <string name="channel_name">food</string>
    <string name ="channel_description">different type of food</string>


@Vlad 2020-06-30 03:27:22

You created a channel with id my_channel_01 but using in notification with id food
Just change this line

NotificationCompat.Builder builder= new NotificationCompat.Builder(this, CHANNEL_ID)

@Sabyasachi Sahu 2020-06-30 03:38:58

Thank you. I changed that now and tried again, but it still does not render. Let me edit that is above code as well.

@Vlad 2020-06-30 03:41:57

@SabyasachiSahu please check if the function createNotificationChannel() is also called in your code before showing notification. It seems is not being called

@Sabyasachi Sahu 2020-06-30 03:52:56

Thank you so much @Vlad this really helps, I somehow missed that.

Related Questions

Sponsored Content

105 Answered Questions

[SOLVED] Close/hide android soft keyboard

23 Answered Questions

[SOLVED] Is there a way to run Python on Android?

29 Answered Questions

[SOLVED] What is 'Context' on Android?

1 Answered Questions

Push notification is not working in android 10

  • 2020-06-15 17:28:26
  • Shadab Azam Farooqui
  • 28 View
  • 0 Score
  • 1 Answer
  • Tags:   android

51 Answered Questions

[SOLVED] Is there a unique Android device ID?

52 Answered Questions

11 Answered Questions

[SOLVED] Proper use cases for Android UserManager.isUserAGoat()?

38 Answered Questions

[SOLVED] How to lazy load images in ListView in Android

17 Answered Questions

[SOLVED] "Debug certificate expired" error in Eclipse Android plugins

Sponsored Content