I am creating an app for a non-English market. Hence, I have to change the font of the notification. I have the following code. But whenever the notification comes, it is blank, there is no logo or text displayed. The small icon is shown at the top.
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
Bitmap bitmapTitle = Bitmap.createBitmap(width - 72, 84, Bitmap.Config.ARGB_8888);
Canvas canvasTitle = new Canvas(bitmapTitle);
Paint paintTitle = new Paint();
paintTitle.setAntiAlias(true);
paintTitle.setSubpixelText(true);
paintTitle.setTypeface(AppApplication.hindiFont); //Font in Hindi
paintTitle.setStyle(Paint.Style.FILL);
paintTitle.setColor(ContextCompat.getColor(context, R.color.positive));
paintTitle.setTextSize(70);
paintTitle.setFakeBoldText(true);
paintTitle.setTextAlign(Paint.Align.LEFT);
canvasTitle.drawText("pqrst", 80, 60, paintTitle);
Bitmap bitmapText = Bitmap.createBitmap(width - 72, 84, Bitmap.Config.ARGB_8888);
//Similar code as above for bitmapText
int notificationID = (int) System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_row);
contentView.setImageViewBitmap(R.id.rnotification_iv_title, bitmapTitle);
contentView.setImageViewBitmap(R.id.rnotification_iv_text, bitmapText);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification.Builder notificationBuilder = new Notification.Builder(context);
Notification notification = notificationBuilder
.setSmallIcon(R.drawable.small_icon)
.setPriority(Notification.PRIORITY_HIGH)
.setSound(alarmSound)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
.setStyle(new Notification.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_image)))
.build();
notification.contentIntent = pendingIntent;
notification.contentView = contentView;
notificationManager.notify(notificationID, notification);
This is the xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_notification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dp">
<ImageView
android:id="@+id/rnotification_iv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_alignParentTop="true"/>
<ImageView
android:id="@+id/rnotification_iv_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="@+id/rnotification_iv_title"
android:layout_alignParentLeft="true"/>