【问题标题】:Android notification small icon安卓通知小图标
【发布时间】: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 代替?

标签: android android-geofence


【解决方案1】:

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

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

【讨论】:

  • 我在drawable中做了一个图标,但它仍然说没有小图标。
  • 你可以试试 NotificationCompat.Builder
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-30
  • 2015-12-31
  • 2011-07-20
  • 2017-12-01
  • 2011-12-15
  • 1970-01-01
相关资源
最近更新 更多