Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android customize foreground service notification

How to customize foreground service notification? I tried:

private void startForegoundService() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(),
            R.layout.custom_notification);
    Notification.Builder mBuilder = new Notification.Builder(this)
            .setContent(remoteViews);

    startForeground(mforegroundNotificationId, mBuilder.build());
}

Where R.layout.custom_notification is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/notification_layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#7777"
    android:padding="3dp" >

    <ImageView
        android:id="@+id/button_enable_alarm"
        android:layout_width="44dp"
        android:layout_height="44dp"
        android:layout_marginRight="10dp"
        android:contentDescription="Eye"
        android:src="@drawable/action_enable_alarm" />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF"
        android:textSize="24sp" />

</LinearLayout>

But it doesn't have any effect. I need customize exactly foreground service notification. Not just "fake" notification for service.

like image 680
Maxim Metelskiy Avatar asked Feb 07 '15 14:02

Maxim Metelskiy


1 Answers

Problem is fixed by adding small icon value. Full code:

Notification.Builder mBuilder = new Notification.Builder(this).setSmallIcon(R.drawable.custom_small_icon).setContent(remoteViews);
like image 141
Maxim Metelskiy Avatar answered Oct 09 '22 05:10

Maxim Metelskiy