学习通知中遇到的一些问题

使用通知不能懒
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle(“Title”)
.setContentText(“text”)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.build();
manager.notify(ID_NOTIFICATION,notification);
特别注意
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
这两句话一定不能省去,他们是用来控制图片的大小的就是下图的灰色和绿色的安卓的地方
在这里插入图片描述

少了他们两个这个程序就无法正常运行
在这里插入图片描述
会出现这种情况并且报出以下错误
在这里插入图片描述
build()一定是在最后才建立的!!!

猜你喜欢

转载自blog.csdn.net/cuipengfei626/article/details/89503952