【发布时间】:2018-02-19 14:18:00
【问题描述】:
我正在 Android Studio 中制作一个带有通知的地理围栏应用程序。但是我遇到了通知没有显示的问题。它说它没有小图标,但我确实将它包含在我的代码中。
错误:02-19 15:06:42.276 1260-1260/? E/NotificationService:没有 发布不带小图标的通知:Notification(channel=null pri=2 contentView=null 振动=[0] 声音=null 默认值=0x0 标志=0x91 颜色=0x00000000 vis=PRIVATE) 02-19 15:06:42.276 1260-1260/? E/NotificationService:警告:在未来的版本中,这将崩溃 应用程序:com.koo.lightmanager 02-19 15:06:42.277 1260-1260/? E/NotificationService:创建带有模式的振动波形时出错: [0]
代码:
private void sendNotification(String title, String content) {
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle(title)
.setContentText(content);
NotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this,MapsActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMUTABLE);
builder.setContentIntent(contentIntent);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
manager.notify(new Random().nextInt(),notification);
}
【问题讨论】:
-
您是否尝试过使用 NotificationCompat.Builder 代替?