Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't expand RemoteViews for: StatusBarNotification

This question has been asked before but none of the answers helped me hence posting my case.

I am trying to build a custom notification using a layout file. But I get the following error:

android.app.RemoteServiceException: Bad notification posted from package com.eswaraj.app.eswaraj: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.eswaraj.app.eswaraj user=UserHandle{0} id=8888 tag=null score=0: Notification(pri=0 contentView=com.eswaraj.app.eswaraj/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x0 kind=[null]))

My layout file is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left">

<com.makeramen.RoundedImageView
    android:id="@+id/nImage"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/profile_image"
    android:padding="15dp"
    android:scaleType="fitCenter"
    app:riv_corner_radius="30dip"
    app:riv_border_width="2dip"
    app:riv_border_color="#333333"
    app:riv_mutate_background="true"
    app:riv_oval="true"/>

<TextView
    android:id="@+id/nTitle"
    android:text="eSwaraj: Your voice is heard"
    android:layout_toRightOf="@+id/nImage"
    android:paddingTop="12dp"
    android:textSize="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/nMessage"
    android:layout_below="@+id/nTitle"
    android:layout_toRightOf="@+id/nImage"
    android:text="Your comaplaint viewed"
    android:textSize="15dp"
    android:paddingTop="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/nTime"
    android:layout_toRightOf="@+id/nImage"
    android:layout_below="@+id/nMessage"
    android:textSize="13dp"
    android:paddingTop="5dp"
    android:text="12:23PM"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

And I am sending notification as follows:

public void sendNotification(Context caller, Class<?> activityToLaunch, Bitmap icon,   GcmMessageDto gcmMessageDto, int id) {
        Intent toLaunch;
        RemoteViews remoteViews = new RemoteViews(caller.getPackageName(), R.layout.notification);
        if(activityToLaunch != null) {
            toLaunch = new Intent(caller, activityToLaunch);
       }
       else {
            toLaunch = new Intent();
        }
        PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);

        NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(caller)
                    .setSmallIcon(android.R.drawable.ic_notification_overlay)
                    .setContentIntent(intentBack);

        remoteViews.setTextViewText(R.id.nMessage, gcmMessageDto.getMessage());
        remoteViews.setTextViewText(R.id.nTime, new Date().toString());
        if(icon != null) {
            remoteViews.setImageViewBitmap(R.id.nImage, icon);
        }
        mBuilder.setContent(remoteViews);

        notifier.notify(id, mBuilder.build());
    }

Any help would be appreciated.

like image 867
vaibhav Avatar asked Jan 11 '15 18:01

vaibhav


1 Answers

Shortly put, the

com.makeramen.RoundedImageView

is messing with your job.

Not all views can be used in RemoteViews which are used for building custom notifications. According to this official page only the following can be used for creating RemoteViews:

  • FrameLayout
  • LinearLayout
  • RelativeLayout
  • GridLayout
  • AnalogClock
  • Button
  • Chronometer
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView
  • ViewFlipper
  • ListView
  • GridView
  • StackView
  • AdapterViewFlipper

So you must find a workaround for your modified ImageView class and use plain ImageView instead.

like image 127
Iman Akbari Avatar answered Sep 26 '22 00:09

Iman Akbari