Android: notification from BroadcastReceiver-ThrowExceptions

Exception or error:

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?

How to solve:

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

Leave a Reply

Your email address will not be published. Required fields are marked *