我正在使用此代码在我的android应用程序中显示通知。在所有android版本中都可以正常工作,但是在Android 9中没有显示通知。
我试图用不同的方法来实现这一点,但没有任何效果。
Greatest Hits
谢谢..
答案 0 :(得分:0)
您好,这是一个很晚的答案,但我仍然想在代码中以及在工作代码段中标记错误,以便它可以帮助其他人。
您在showNotification(..)函数中有两个NotificationManager实例,在createChannel()函数中有另一个。您必须在notificationManager的同一实例中创建频道,以便您的工作代码如下:
public void showNotification(String heading, String description, String imageUrl, Intent intent){
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"channelID")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(heading)
.setContentText(description)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = 1;
createChannel(notificationManager);
notificationManager.notify(notificationId, notificationBuilder.build());
}
public void createChannel(NotificationManager notificationManager){
if (Build.VERSION.SDK_INT < 26) {
return;
}
NotificationChannel channel = new NotificationChannel("channelID","name", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("Description");
notificationManager.createNotificationChannel(channel);
}
呼叫方式:
showNotification("Heading","Description","",new Intent(this,MainActivity.class));
结果: Tensorflow - ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer`