0

我使用 RemoteViews 进行本地通知。我无法解决这个问题,因为我的代码不会出现这个错误

请点击设备安卓版本

异常细节;

java.lang.Exception: android.app.RemoteServiceException: Bad notification posted from package com.package.name: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.package.name user=UserHandle{0} id=2010 tag=null score=10: Notification(pri=1 contentView=com.package.name/0x1090064 vibrate=[0] sound=content://settings/system/notification_sound defaults=0x0 flags=0x10 kind=[null]))
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5095)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)

        at com.package.name.activity.CustomErrorActivity.onCreate(CustomErrorActivity.java:30)
        at android.app.Activity.performCreate(Activity.java:5237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
        at android.app.ActivityThread.access$800(ActivityThread.java:138)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5095)
        at java.lang.reflect.Method.invokeNative(Method.java:-2)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
        at dalvik.system.NativeStart.main(NativeStart.java:-2)

我的远程视图 XML;

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/status_bar_latest_event_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:paddingTop="3dp">

<ImageView
    android:id="@+id/big_picture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="78dp"
    android:foregroundGravity="bottom"
    android:scaleType="fitCenter"
    android:src="@drawable/prayer_times_notf_1" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/big_icon"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:paddingLeft="3dp"
        android:scaleType="fitCenter"
        android:src="@drawable/app_logo" />

    <LinearLayout
        android:id="@+id/titleContainer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:singleLine="true"
            android:textColor="@color/black"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:singleLine="true"
            android:text="@string/app_name"
            android:textColor="#999999"
            android:textSize="16sp" />

    </LinearLayout>

</LinearLayout>

<LinearLayout
    android:id="@+id/buttonContainer"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/big_picture"
    android:layout_marginTop="-55dp"
    android:background="#D9FFFFFF"
    android:orientation="horizontal"
    android:weightSum="2">

    <RelativeLayout
        android:id="@+id/remoteview_setting_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:visibility="visible">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/settings"
                android:tint="@color/colorPrimaryDark" />

            <TextView
                android:id="@+id/remote_setting_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:text="@string/settings"
                android:textColor="@color/colorPrimaryDark" />

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/remoteview_mute_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/ic_volume_off_black_24dp"
                android:tint="@color/colorPrimaryDark" />

            <TextView
                android:id="@+id/remote_mute_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/alarm_mute"
                android:textColor="@color/colorPrimaryDark" />

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/remoteview_reminder_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/ten_minute_later"
                android:tint="@color/colorPrimaryDark" />

            <TextView
                android:id="@+id/remote_ten_min_later"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/alarm_dialog_snooze"
                android:textColor="@color/colorPrimaryDark" />

        </LinearLayout>

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/remoteview_share_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/ic_share"
                android:tint="@color/colorPrimaryDark" />

            <TextView
                android:id="@+id/remote_view_share"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/share"
                android:textColor="@color/colorPrimaryDark" />

        </LinearLayout>

    </RelativeLayout>

</LinearLayout>

和Java;

RemoteViews remoteViews = remoteView(_mContext.getResources().getString(R.string.app_opened_notf_title), R.drawable.notf_wallpaper, false);
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
            notification.bigContentView = remoteViews;


private RemoteViews remoteView(String title, int imageResource, boolean hideButtons) {
    RemoteViews remoteViews = new RemoteViews(_mContext.getPackageName(), R.layout.view_big_notification_picture);
    remoteViews.setImageViewBitmap(R.id.big_picture, BitmapFactory.decodeResource(_mContext.getResources(), imageResource));
    remoteViews.setTextViewText(R.id.title, title);
    remoteViews.setTextViewText(R.id.remote_setting_btn, _mContext.getString(R.string.settings));
    remoteViews.setTextViewText(R.id.remote_mute_btn, _mContext.getString(R.string.alarm_mute));
    remoteViews.setTextViewText(R.id.remote_ten_min_later, _mContext.getString(R.string.alarm_dialog_snooze));
    remoteViews.setTextViewText(R.id.remote_view_share, _mContext.getString(R.string.share));
    remoteViews.setViewVisibility(R.id.buttonContainer, (hideButtons) ? View.VISIBLE : View.GONE);
    return remoteViews;
}

我该如何解决这个问题?

4

0 回答 0