Comments (3)
Error showing notification for service
java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE)
at com.android.server.am.ServiceRecord$1.run(ServiceRecord.java:532)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
普通的Notification
notification = new Notification();
startForeground(notificationId, notification);
Process: com.xtc.im.phonesample:push, PID: 29711
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
设置channel的Notification
NotificationChannel channel = new NotificationChannel("id","name", NotificationManager.IMPORTANCE_LOW);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
notification = new Notification.Builder(this,"im_channel_id")
.setSmallIcon(R.drawable.ic_launcher) // the status icon
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentText("IM服务正在运行") // the contents of the entry
.build();
我靠,是这个资源res/mipmap就这样,但是用drawable就好了,不过还不是指定的图片
Unable to load resource 0x7f030000 from pkg=com.xtc.im.phonesample
android.content.res.Resources$NotFoundException: Drawable com.xtc.im.phonesample:mipmap/ic_launcher with resource ID #0x7f030000
Caused by: android.content.res.Resources$NotFoundException: File res/mipmap-anydpi-v26/ic_launcher.xml from drawable resource ID #0x7f030000
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:820)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
at android.content.res.Resources.getDrawable(Resources.java:819)
at android.graphics.drawable.Icon.loadDrawableInner(Icon.java:324)
at android.graphics.drawable.Icon.loadDrawable(Icon.java:277)
at android.graphics.drawable.Icon.loadDrawableAsUser(Icon.java:388)
Process: com.xtc.im.phonesample:push, PID: 29379
android.app.RemoteServiceException: Bad notification posted from package com.xtc.im.phonesample: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.xtc.im.phonesample id=0x7f030000) visible user=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
from androidbox.
最后的姿势
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(pushServiceIntent);
}else {
componentName = context.startService(pushServiceIntent);
}
// service的onCreate
NotificationChannel channel = new NotificationChannel("im_channel_id","System", NotificationManager.IMPORTANCE_LOW);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
notification = new Notification.Builder(this,"im_channel_id")
.setSmallIcon(R.drawable.ic_launcher) // the status icon
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentText("IM服务正在运行") // the contents of the entry
.build();
startForeground(notificationId, notification)
from androidbox.
what’s the type definition about "notificationId"?
from androidbox.
Related Issues (20)
- Toast Show的时候出现 BadTokenException: Unable to add window -- token
- java.lang.IllegalStateException: Fragment already added HOT 2
- ANR: "main" prio=5 tid=1 WaitingForGcToComplete HOT 2
- Exception: The specified message queue synchronization barrier token has not been posted or has already been removed.
- ExceptionInInitializerError HOT 2
- 为什么Receiver不允许进行BindService
- Fragment生命周期
- SQLite多线程问题 HOT 3
- 《Android应用性能优化》 HOT 1
- 内存优化 HOT 1
- Native闪退 HOT 1
- java.lang.IllegalStateException: The specified child already has a parent.
- RxJava线程 HOT 1
- Service启动成功onCreate和onStartCmmand都不回调
- CursorWindowAllocationException HOT 1
- SharedPreferences解析
- Component class com.huawei.hms.support.api.push.PushEventReceiver does not exist in com.xtc.watch HOT 2
- SQLite查询操作源码分析:从 IllegalArgumentException:the bind value at index 2 is null 说起
- startActivityForResult的坑
- java.lang.IllegalArgumentException: pointerIndex out of range HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidbox.