In case of Long Text Notifications only single line (Trimmed Text) is appearing on MI/XIAOMI Phone

801 views Asked by At

If text length is more than 50 characters then only one line is shown on Notification bar in case of MI/XIAOMI phone but on other phones its working fine

FYI : We are already using big Text Style notifications

Any work around

1

There are 1 answers

1
Panache On

You have to use custom Notifications for Xiaomi and this will help other mobiles also where developers have over customized OS. Try this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/images"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/titles"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_toEndOf="@+id/images"
        android:text="Title"
        android:textColor="@color/colorAccent"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/notvalue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/titles"
        android:layout_below="@+id/titles"
        android:layout_toEndOf="@id/images"
        android:text="Message"
        android:textColor="@color/colorPrimary" />
</RelativeLayout>

Notification Code:

 RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.cusnot);
            remoteViews.setTextViewText(R.id.titles, title);
            remoteViews.setTextViewText(R.id.notvalue, message);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());

            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0);
            builder.setContent(remoteViews)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .build();
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(1, builder.build());