[英]Android notification small icon
我正在使用Android Studio中的通知制作Geo Fencing應用程序。 但是我有一個問題,通知沒有顯示,它說它沒有一個小圖標,但是我確實在代碼中包含了它。
錯誤:02-19 15:06:42.276 1260-1260 /? E / NotificationService:不發布帶有小圖標的通知:通知(channel = null pri = 2 contentView = null振動= [0]聲音= null默認值= 0x0標志= 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);
}
將圖標放在Drawable文件夾中,它將起作用
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_round)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.