【发布时间】:2020-09-07 22:27:39
【问题描述】:
你好有人可以告诉我如何在不收到此异常的情况下发出通知:java.lang.IllegalArgumentException:无效通知(没有有效的小图标):通知(频道=null pri=0 contentView=null vibrate=null sound=null默认值=0x0 标志=0x0 颜色=0x00000000 vis=PRIVATE)
代码:
public void notifyThis(String text) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Intent notificationIntent = new Intent(this, RegisterActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
if(Build.VERSION.SDK_INT >= 26) {
//When sdk version is larger than26
String id = "channel_1";
String description = "143";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel channel = new NotificationChannel(id, description, importance);
channel.enableLights(true);
channel.enableVibration(true);//
manager.createNotificationChannel(channel);
Notification notification = new Notification.Builder(MapsActivity.this, id)
.setCategory(Notification.CATEGORY_MESSAGE)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.screenmec))
.setContentTitle("MECTS.SA")
.setContentText(text)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build();
manager.notify(1, notification); }
else {
//When sdk version is less than26
Notification notification = new NotificationCompat.Builder(MapsActivity.this)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.screenmec))
.setContentTitle("MECTS.SA")
.setContentText(text)
.setContentIntent(contentIntent)
.build();
manager.notify(1,notification); }
NotificationManager mannager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mannager.notify(0,builder.build());
}
【问题讨论】:
标签: java android firebase android-studio exception