Getting error Attempted to start a foreground service (xxx) with a broken notification (no icon: Notification(pri=0 contentView=null ---

1

I do not understand this error message in Android Studio. Looking at the source code this error is caused by the small icon being null. But I set the icon (both large and small) and the notification is present WITH my icon. I even used the Asset Studio to create this icon specifically for notifications.

There are a lot of other posts on this topic but they all seem related to those trying to HIDE the notification in some way. I want it so that my service is not killed by Android!

Here is the full error

Attempted to start a foreground service (ComponentInfo{com.lni.pchademophg/com.lni.pchademophg.BaseManager}) with a broken notification (no icon: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE secFlags=0x0 secPriority=0))

Why the error? ( I guess I shouldn't complain, everything works as I need it to work ... at least it appears so, but the error is unsettling and I would like to understand it.) This error is occurring on a 6.0.1 device (have not tried a 10 yet)

Here is my code which is in the 'onsStartCommand()' method of the service:

    @Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
    {
        createNotificationChannel();

        Notification.Builder builder = new Notification.Builder(context, mChannel.getId())
                .setContentTitle(getString(R.string.app_name))
                .setSmallIcon(R.drawable.ic_stat_name)
                .setContentText("Pcha Personal Health Gateway")
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                        R.drawable.ic_stat_name))
                .setAutoCancel(true);

        Notification notification = builder.build();
        startForeground(NOTIFICATION_ID, notification);
    }
    else
    {
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(context, "BtleScanChannel");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        {
            notificationBuilder.setPriority(NotificationManager.IMPORTANCE_LOW);
        }
        notificationBuilder.setContentTitle(getString(R.string.app_name))
                .setContentTitle(getString(R.string.app_name))
                .setContentText("Pcha Personal Health Gateway")
                .setSmallIcon(R.drawable.ic_stat_name)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                        R.drawable.ic_stat_name));
        startForeground(NOTIFICATION_ID, notificationBuilder.build());
    }

    return START_STICKY; 
}

Any ideas? What are the consequences?

android-service
android-notifications

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0