使用ImageView发布的错误通知

时间:2014-02-12 15:08:32

标签: android android-layout android-intent android-notifications android-remoteview

我正在尝试在Android 2.3.3上构建通知。 我需要一个自定义布局,我不能使用Notification Builder。 这是通知的布局:

R.layout.notification_upload

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative_notification_upload"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageview_icon"
        android:layout_height="match_parent"
        android:layout_marginRight="10dp"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher"
        android:contentDescription="@string/icon" >
    </ImageView>

    <ProgressBar
        android:id="@+id/progress_bar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:indeterminate="true" >
    </ProgressBar>

</RelativeLayout>

这是通知的代码:

NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent = new Intent(context, HomeActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
        intent, 0);
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_upload);

Notification notification = new Notification();

notification.when = 0;
notification.icon = R.drawable.ic_launcher;
notification.contentIntent = pendingIntent;
notification.contentView = contentView;

notificationManager.notify(0, notification);

我收到: 从包中发布错误通知:无法展开RemoteViews ... 我哪里出错了?我可以在通知中使用ImageView吗?

0 个答案:

没有答案