Android setContent不适用于NotificationCompat.Builder

Android setContent不适用于NotificationCompat.Builder,android,service,notifications,Android,Service,Notifications,我想在服务中将自定义布局显示为通知 以下是我在服务类中的方法: private void fireNotification() { Log.d("Clock", "Fire!"); if (this.remoteViews == null) { Log.d("Clock", "!=null"); remoteViews = new RemoteViews(getPackageName(), R.layout.cus

我想在服务中将自定义布局显示为通知

以下是我在服务类中的方法:

private void fireNotification() {
    Log.d("Clock", "Fire!");
    if (this.remoteViews == null) {
        Log.d("Clock", "!=null");

        remoteViews = new RemoteViews(getPackageName(),
                R.layout.custom_notification);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher).setContent(
                remoteViews);

        // Creates an explicit intent for an Activity in your app
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, 0);
        mBuilder.setContentIntent(contentIntent);

        startForeground(1, mBuilder.build());
    }
}
自定义通知.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="3dp"
          android:background="@android:color/white"
          >

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:textColor="#000" />

<ImageView android:id="@+id/image"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_marginRight="10dp"
          android:background="@android:drawable/ic_menu_help"
          />
</LinearLayout>

但是默认通知会显示我的图标! 怎么了

编辑:
我在模拟器上运行我的应用程序,它在安卓4上运行,但在我的姜饼手机上它不工作

您必须将所需图像设置为“图像视图”自定义布局中的内容

contentView.setImageViewResource(R.id.image, R.drawable.icon);
根据,NotificationCompat.Builder不支持Android 2.x上的setContent

错误页面中可能的解决方法(#6):


notification=builder.build();
notification.contentView=contentView;

显示您的自定义布局代码here@RajaReddyPolamReddy编辑!那么这有什么问题呢?我认为是API级别的问题。它在安卓4中工作,但在2.3.x中不工作