xjdeng
xjdeng

Reputation: 49

Ignoring notification with

Edit: It's fixed even though my code isn't perfect. I forgot to register this BroadCastReceiver in my Android Manifest file. Face Palm.


I'm having trouble getting my notification to work. It would help if I get some meaningful error message but I have no idea how to debug this.

Here's the code of the broadcast receiver:

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ThisDoesNotWork extends BroadcastReceiver{

    private Intent myIntent;
    private PendingIntent myPending;
    private static final int MY_NOTIFICATION_ID = 1;
    private final CharSequence text1 = "Text1";
    private final CharSequence text2 = "Text2!";

    @Override
    public void onReceive(Context context, Intent intent) {
        myIntent = new Intent(context, MainActivity.class);
        myPending = PendingIntent.getActivity(context, 0, myIntent,
                Intent.FLAG_ACTIVITY_NEW_TASK);
        Notification.Builder myNote = new Notification.Builder(context).setTicker(
                "Take a Selfie!")
                .setSmallIcon(android.R.drawable.stat_sys_warning)
                .setAutoCancel(true).setContentTitle(text1)
                .setContentText(text2)
                .setContentIntent(myPending);
        NotificationManager mNotify = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Log.i("Receiver", "Notification created.");
        mNotify.notify(MY_NOTIFICATION_ID,myNote.getNotification());
        Log.i("Receiver", "Notification sent.");
    }

}

My program compiles but this notification gets ignored.

The error message I get is: Ignoring notification with icon==0; Notification(contentView =null vibrate=null...

Can anyone bring me 1 step closer to a solution?

Upvotes: 0

Views: 838

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200020

Per the required notification contents, you must include:

It appears you are missing the content title, causing your notification to get ignored.

Upvotes: 2

Related Questions