android 自己定义通知栏遇到的问题


首先看报错信息:

E/AndroidRuntime(12220): FATAL EXCEPTION: main

E/AndroidRuntime(12220): Process: gn.com.android.update, PID: 12220

E/AndroidRuntime(12220): android.app.RemoteServiceException: Bad notification posted from package gn.com.android.update: Couldn't expand RemoteViews for: StatusBarNotification(pkg=gn.com.android.update user=UserHandle{0} id=1 tag=null score=0 key=0|gn.com.android.update|1|null|10038: Notification(pri=0 contentView=gn.com.android.update/0x7f03000a vibrate=null sound=null defaults=0x0 flags=0x20 color=0x00000000 vis=PRIVATE))


E/AndroidRuntime(12220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)

E/AndroidRuntime(12220): at android.os.Handler.dispatchMessage(Handler.java:106)


E/AndroidRuntime(12220): at android.os.Looper.loop(Looper.java:189)


E/AndroidRuntime(12220): at android.app.ActivityThread.main(ActivityThread.java:5532)


E/AndroidRuntime(12220): at java.lang.reflect.Method.invoke(Native Method)


E/AndroidRuntime(12220): at java.lang.reflect.Method.invoke(Method.java:372)


E/AndroidRuntime(12220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)


E/AndroidRuntime(12220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)



代码例如以下:  

           通知栏定义布局中的一个控件这样写的:

            <ImageView
        android:id="@+id/notificationImage"
        android:layout_width="@android:dimen/notification_large_icon_width"
        android:layout_height="@android:dimen/notification_large_icon_height"
        android:scaleType="center"
        android:clickable="true"
        android:background="@*android:drawable/notify_panel_notification_icon_bg_tile"
        android:src="@drawable/stat_sys_download_anim0" 
        />

                  

         java中代码这样:

        if (null == mNotification) {
            mContentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SettingUpdate.class), 0);
            // new一个通知对象
            mNotification = new Notification(R.drawable.stat_sys_download_anim0,
                    getString(R.string.notify_auto_update_title), System.currentTimeMillis());
            mNotification.flags = Notification.FLAG_NO_CLEAR;
        }
        mNotification.icon = R.drawable.stat_sys_download_anim0;


       解决方法:

            把 android:src="@drawable/stat_sys_download_anim0" 这句话删除掉。就没有该问题了,就不报错,可是显示为黑色。初步预计是systemui问题, 如今不知道原因,请大神看到回复下,谢谢


          兴许编辑:

                  后面发现 android:background="@*android:drawable/notify_panel_notification_icon_bg_tile" 行代码出问题,原因是androidL系统中没有这个资源。kk上是编译通过的,android L上编译就出现那问题。

。。

改动就能够了,,,万里寻他千百度啊。

。。。不easy啊。。。



原文地址:https://www.cnblogs.com/yxwkf/p/5099794.html