Android通知小图标

时间:2018-02-19 14:18:00

标签: android android-geofence

我正在使用Android Studio中的通知制作地理围栏应用程序。但是我遇到的问题是通知没有显示出来。它说它没有小图标,但我确实在我的代码中包含了它。

  

错误:02-19 15:06:42.276 1260-1260 /? E / NotificationService:没有   发布没有小图标的通知:通知(channel = null   pri = 2 contentView = null vibrate = [0] sound = null defaults = 0x0 flags = 0x91   color = 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);
}

1 个答案:

答案 0 :(得分:0)

将图标放在Drawable文件夹中,它将起作用

Notification.Builder builder = new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher_round)