I have a head-up notification code that works perfectly when triggered from an Activity. I tried triggering using the same code from a service and it is not working. Please note code is ok (as it works in the Activity), I tried foreground service, but still no luck. Normal notification is fine from both service and activity. I also checked that no limits are reached (I know there could be a time guard so I test with single notification once in 5 min)
Any ideas what could be wrong?
public void notifyFromTask(TaskStateData state){
NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx, HEADUP_CHANNEL_ID);
builder.setContentTitle(state.mTitle);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(state.mText));
switch (state.mTaskType){
case NetworkTask2.DOWNLOAD_TASK:
builder.setSmallIcon(R.drawable.ic_menu_download);
break;
case NetworkTask2.UPLOAD_TASK:
builder.setSmallIcon(R.drawable.ic_menu_upload);
break;
case NetworkTask2.SYNC_TASK:
builder.setSmallIcon(R.drawable.ic_menu_sync);
break;
default:
builder.setSmallIcon(R.drawable.ic_menu_sync);
break;
}
builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.drawable.icon));
builder.setColor(mCtx.getResources().getColor(R.color.colorPrimaryDark));
builder.setGroup(mCtx.getString(R.string.app_name));
builder.setContentIntent(getPendingIntent());
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setDefaults(NotificationCompat.DEFAULT_SOUND | NotificationCompat.DEFAULT_VIBRATE);
mNM.notify(state.mTaskId, builder.build());
}