Search code examples
javaandroidandroid-notifications

Android notifications from a BroadcastReceiver not showing


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