前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >android 自己定义通知栏遇到的问题「建议收藏」

android 自己定义通知栏遇到的问题「建议收藏」

作者头像
全栈程序员站长
发布2022-07-07 18:10:54
4920
发布2022-07-07 18:10:54
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是全栈君。

首先看报错信息:

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://javaforall.cn/116437.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档