Jim
Jim

Reputation: 9234

Android: notification from BroadcastReceiver

I have an alarm manager that starts a broadcast receiver. Here is my broadcast receiver:

public class AlarmBrodcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent arg1) {
        showNotification(context);
    }

    private void showNotification(Context context) {
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, MyActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                .setSmallIcon(0)
                .setContentTitle("My notification")
                .setContentText("Hello World!");
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        mBuilder.setAutoCancel(true);
        NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());

    }  
}

The broadcast starts in time, but there is no notification, only sound. Where is the text? What's wrong? Is it because I'm using API 10 and the support library?

Upvotes: 22

Views: 30675

Answers (1)

Jim
Jim

Reputation: 9234

Oh, I found the problem. The problem is in .setSmallIcon(0)...When I set some real resource, its ok, notification appear...

Upvotes: 23

Related Questions