Android 不能';t展开远程视图以进行:状态通知

Android 不能';t展开远程视图以进行:状态通知,android,android-layout,notifications,remoteview,Android,Android Layout,Notifications,Remoteview,以前有人问过这个问题,但没有一个答案对我有帮助,因此我把我的情况公布了出来 我正在尝试使用布局文件构建自定义通知。但我得到了以下错误: android.app.RemoteServiceException:从发布的错误通知 包com.eswaraj.app.eswaraj:无法展开以下项的远程视图: StatusBarNotification(pkg=com.eswaraj.app.eswaraj user=UserHandle{0} id=8888标记=null分数=0:通知(pri=0 co

以前有人问过这个问题,但没有一个答案对我有帮助,因此我把我的情况公布了出来

我正在尝试使用布局文件构建自定义通知。但我得到了以下错误:

android.app.RemoteServiceException:从发布的错误通知 包com.eswaraj.app.eswaraj:无法展开以下项的远程视图: StatusBarNotification(pkg=com.eswaraj.app.eswaraj user=UserHandle{0} id=8888标记=null分数=0:通知(pri=0 contentView=com.eswaraj.app.eswaraj/0x7f030052振动=null声音=null 默认值=0x0标志=0x0种类=[null]))

我的布局文件是:

<?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>

我发送通知如下:

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());
    }
public void sendNotification(上下文调用方、类activityToLaunch、位图图标、GcmMessageDto GcmMessageDto、int-id){
意图发射;
RemoteViews RemoteView=新的RemoteView(caller.getPackageName(),R.layout.notification);
如果(activityToLaunch!=null){
toLaunch=新意图(调用者、活动toLaunch);
}
否则{
toLaunch=新意图();
}
pendingent intentBack=pendingent.getActivity(调用者,0,toLaunch,0);
NotificationManager通知程序=(NotificationManager)caller.getSystemService(Context.NOTIFICATION\u服务);
通知相容建筑商mBuilder=
新建NotificationCompat.Builder(调用方)
.setSmallIcon(android.R.drawable.ic_通知_覆盖)
.setContentIntent(intentBack);
setExtViewText(R.id.nMessage,gcmMessageDto.getMessage());
setExtViewText(R.id.nTime,new Date().toString());
如果(图标!=null){
setImageViewBitmap(R.id.nImage,图标);
}
mBuilder.setContent(远程视图);
notifier.notify(id,mBuilder.build());
}
任何帮助都将不胜感激。

简而言之

com.makeramen.RoundedImageView

这会影响你的工作

并非所有视图都可以在用于生成自定义通知的RemoteView中使用。根据,只有以下内容可用于创建RemoteView:

  • 框架布局
  • 线性布局
  • 相对论
  • 网格布局
  • 模拟时钟
  • 钮扣
  • 天文钟
  • 图像按钮
  • 图像视图
  • 进度条
  • 文本视图
  • 视窗翻转器
  • 列表视图
  • 网格视图
  • 斯塔克维尤
  • 适配器交换机

因此,您必须为修改后的ImageView类找到一个解决方法,并改用普通ImageView。

我也有同样的问题,我使用了自定义TextView,使用stock TextView解决了我的问题。

我也有同样的问题。根据公认的答案,通知中可以使用特定的控制措施。我在我的布局中有一个通知视图,如下所示

<View
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.04"/>


这是导致坠机的原因。我把它取了下来,效果很好。希望它对其他人有所帮助。

我在使用约束布局时遇到了同样的问题,然后我只是按照文档进行操作,并更改为线性布局,结果成功了。

在我的情况下,我使用的是
AppCompatImageView
。切换到
ImageView
解决了此问题。请从链接中添加一些附加信息,因为链接本身将来可能会中断