发布了错误通知

时间:2016-08-17 10:05:50

标签: android notifications android-notifications

我已经创建了自定义通知。并获得以下例外。我的布局中没有任何自定义视图或点击事件。

例外:

  

致命异常:android.app.RemoteServiceException:错误通知   从包com.myapp发布:无法展开RemoteViews:   StatusBarNotification(pkg = com.myapp user = UserHandle {0} id = 191 tag = null   得分= 0键= 0 | com.myapp | 191 | null | 10127:通知(pri = 0   内容查看= com的

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@color/ro_notification_bg"
    android:layout_height="wrap_content">

    <FrameLayout
        android:id="@+id/profile_image_super_container"
        android:layout_marginStart="@dimen/low_margin"
        android:layout_width="54dp"
        android:layout_height="54dp"
        android:layout_centerVertical="true">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/very_low_margin"
            android:id="@+id/profile_image_container">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/notification_image_bg"
                android:id="@+id/profile_tile_layout">

                <TextView
                    android:id="@+id/profile_letter_tile"
                    android:textSize="@dimen/rs_name_tile_size"
                    android:fontFamily="sans-serif-light"
                    android:layout_centerInParent="true"
                    android:textColor="@color/white"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            </RelativeLayout>

            <ImageView android:id="@+id/profile_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:layout_gravity="center" />

        </FrameLayout>

        <FrameLayout
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:id="@+id/badge_container"
            android:background="@drawable/notification_badge_bg"
            android:layout_gravity="end|bottom">

            <TextView
                android:id="@+id/badge_letter_tile"
                android:textSize="12sp"
                android:layout_gravity="center"
                android:fontFamily="sans-serif-medium"
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        </FrameLayout>

    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginStart="@dimen/low_margin"
        android:layout_toEndOf="@+id/profile_image_super_container"
        android:orientation="vertical">

        <TextView
            android:id="@+id/notification_title"
            android:textSize="@dimen/textSizePrimary"
            android:fontFamily="sans-serif"
            android:textColor="@color/textcolorPrimary"
            android:text="My App"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <TextView
            android:id="@+id/notification_subtext"
            android:textSize="@dimen/textSizeSub1"
            android:fontFamily="sans-serif"
            android:text="Unlock device"
            android:textColor="@color/textcolorSecondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>

</RelativeLayout>

我的java代码:

NotificationManager notificationManager = (NotificationManager) MyApplication.getContext()
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent = new Intent(MyApplication.getContext(), Overlay.class);
        intent.putExtra(ORIGIN_NOTIFICATION, true);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                |Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS|Intent.FLAG_ACTIVITY_NO_HISTORY);
        PendingIntent pendingIntent = PendingIntent.getActivity(MyApplication.getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        RemoteViews remoteViews = new RemoteViews(MyApplication.getContext().getPackageName(), R.layout.my_notification);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(MyApplication.getContext())
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.drawable.notification_logo)
                .setContent(remoteViews);

        remoteViews.setTextViewText(R.id.notification_subtext, MyApplication.getContext().getString(R.string.unlock_phone));
        remoteViews.setTextViewText(R.id.badge_letter_tile, String.valueOf(12));
        remoteViews.setTextViewText(R.id.notification_title, "My phone number");
        Notification notification = builder.build();

        remoteViews.setTextViewText(R.id.profile_letter_tile, "A");

        String imageUrl = Utilities.getProperImageURL();
        if (imageUrl != null) {
        Picasso.with(MyApplication.getContext()).load(Uri.fromFile(new File(imageUrl)))
                    .into(remoteViews, R.id.profile_image, NOTIFICATION_ID, notification);
        } else {
            remoteViews.setImageViewResource(R.id.profile_image, R.drawable.unknown_profile_photo_notification);
        }

        notification.flags |= Notification.FLAG_NO_CLEAR;
        notificationManager.notify(NOTIFICATION_ID, notification);

0 个答案:

没有答案