Fatal Exception: android.app.RemoteServiceException: Bad notification posted Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package com.noti: Couldn't update icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.noti id=0x00000000) visible user=0 )
Notification.Builder mBuilder = new Notification.Builder(context);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
mBuilder.setSmallIcon(convertStringToBitmap(StringUtils.appendDegree("12")));
} else {
mBuilder.setSmallIcon(R.drawable.notification_icon);
}
// Creates an explicit intent for an Activity
Intent resultIntent = new Intent(context, HomeActivity.class);
resultIntent.putExtra(AppConstants.IS_ONGOING, true);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
mBuilder.setContentIntent(resultPendingIntent);
Notification notification =mBuilder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (getComplexNotificationView(context) != null) {
notification.contentView = getComplexNotificationView(context);
}
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
}
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, notification);
private static Icon convertStringToBitmap(String text) {
Paint paint = new Paint(ANTI_ALIAS_FLAG);
paint.setTextSize(100.0f);
paint.setColor(Color.WHITE);
paint.setTextAlign(Paint.Align.LEFT);
float baseline = -paint.ascent(); // ascent() is negative
int width = (int) (paint.measureText(text) + 0.5f); // round
int height = (int) (baseline + paint.descent() + 0.7f);
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawText(text, 0, baseline, paint);
return Icon.createWithBitmap(image);
}