How can I show notification text on icon place?

42 Views Asked by At

I am trying to create an Android application. For that, I want to show a notification in a specific place. So, I use RemoteViews, but now I also want to display that text on my home screen. How can I do that?

Here is some breakdowns of my code:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!-- TextView for displaying speed -->

    <TextView
        android:id="@+id/text_speed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="37dp"
        android:layout_marginTop="7dp"
        android:padding="10dp"
        android:text="70kb"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/text_fmobile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@id/text_speed"
        android:layout_marginStart="212dp"
        android:layout_toEndOf="@id/text_speed"
        android:text="speed : 70kb"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

</RelativeLayout>

I use this Java code to update and show the information

notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_launcher_background)
        .setContentIntent(pendingIntent)
        .setSound(null) // Set notification sound to null to make it silent
        .setCustomContentView(notificationLayout);

I want to show this application icon like that on my home screen:

enter image description here

It now looks like this:

enter image description here

Please provide me some advice on how I can do that using those layout activities.

0

There are 0 best solutions below