最快捷的方法是將以下代碼添加到GCMIntentService.java到onMessage函數中。您正在使用的GCM插件僅接收GCM消息,但您必須自行觸發通知。您還可以嘗試使用cordova插件來顯示狀態欄通知。
protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
String message = extras.getString("message");
String title = extras.getString("title");
Notification notif = new Notification(R.drawable.ic_launcher, message, System.currentTimeMillis());
notif.flags = Notification.FLAG_AUTO_CANCEL;
notif.defaults |= Notification.DEFAULT_SOUND;
notif.defaults |= Notification.DEFAULT_VIBRATE;
Intent notificationIntent = new Intent(context, SomeActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notif.setLatestEventInfo(context, "Title of notification", message, contentIntent);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
mNotificationManager.notify(1, notif);
你能改寫你的問題更清晰?當收到推送通知時,您是否試圖在通知(頂部)欄中顯示圖標? – acj
是的,當收到一個推送通知,然後在通知(頂部)欄中不顯示圖標 – Patel
toadzky下面的答案是正確的。大多數圖書館都會讓您指定收到推送通知時要執行的操作。 – acj