我正在尝试使用 Android 显示通知。以下代码不显示任何内容。我错过了什么吗?没有引发错误并且代码执行,但我没有看到任何对话框或任何指示通知的内容。
NotificationManager mNotificationManager = (NotificationManager)
this.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
Notification n = new Notification.Builder(this.getApplicationContext())
.setContentTitle("Socket Message Received")
.setContentText("My Application")
.setSmallIcon(com.mypackage.app.R.drawable.icon)
.build();
mNotificationManager.notify(5, n);
或者当我直接从 Cordova 插件调用它时
NotificationManager mNotificationManager = (NotificationManager)
cordova.getActivity().getApplicationContext().getSystemService(android.content.Context.NOTIFICATION_SERVICE);
Notification n = new Notification.Builder(cordova.getActivity().getApplicationContext())
.setContentTitle("Socket Message Received")
.setContentText("My Application")
.setSmallIcon(com.mypackage.app.R.drawable.icon)
.build();
mNotificationManager.notify(CM_NOTIFICATION_ID.hashCode(), n);
那么有谁知道为什么这不会显示任何错误?