[SOLVED] Android notifications from a BroadcastReceiver not showing


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

Issue

I want to create a notification (from a BroadcastReceiver – if that makes a difference)

I don’t know why, but It’s just not showing up!

private void showNotification(Context context, String text) {

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.notification_icon)
                        .setContentTitle(getString(R.string.app_name))
                        .setContentText(text)
                        .setAutoCancel(true);

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        mNotificationManager.notify(0, mBuilder.build());

    }

I have tried this (and this)

Solution

Thanks to all answers, but I got it solved unexpectedly. I don’t know which point really solved it, but I tried this: 1. Clean 2. Rebuild 3. Close Android studio 4. Reboot 5. Restart android studio

Answered By – Saman Miran

people found this article helpful. What about you?