Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Custom Notification View Doesn't Show Images

I’m trying show an icon and a text on my notification bar. So I created a new layout for that, however only the text shows up and the icon doesn’t.

This is how I create the notification:

val notification = NotificationCompat.Builder(this, notificationChannelId)
            .setOngoing(true)
            .setContentTitle(getString(R.string.app_name))
            .setCustomBigContentView(RemoteViews(packageName, R.layout.notification_view))
            .setSmallIcon(R.drawable.ic_launcher)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setContentIntent(pendingIntent)
            .build()

And this is my notification layout:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

    <ImageView
        android:id="@+id/ic_someid"
        android:layout_width="15dp"
        android:layout_height="15dp"
        app:srcCompat="@drawable/ic_someicon" />

    <TextView
        android:id="@+id/text_sometext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test..." />
</LinearLayout>

My question is why does the icon doesn’t show up in the notification bar?

>Solution :

Replace app:srcCompat="@drawable/ic_someicon" with android:src="@drawable/ic_someicon". You cannot use app-prefixed attributes with any RemoteViews scenario (custom notifications, app widgets, etc.).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading