收到推送后显示带有消息的提醒。 PhoneGap的

时间:2013-04-02 04:21:23

标签: cordova push-notification phonegap-plugins cordova-2.0.0

我正在使用GitHub-GCM Cordova plugin。我的问题是我收到后无法显示推送消息。

GCMIntentService:

@Override
protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);

Bundle extras = intent.getExtras();
if (extras != null) {
//show alert
}
//...
}

我认为我应该是java代码,因为我不知道如何引用html / js ..但是AlertDialog Builder不起作用。

1 个答案:

答案 0 :(得分:0)

您可以在使用此代码接收推送后显示提醒:

String message = extras.getString("message");
String title = extras.getString("title");
Notification notif = new Notification(android.R.drawable.btn_star_big_on, message, System.currentTimeMillis() );
notif.flags = Notification.FLAG_AUTO_CANCEL;
notif.defaults |= Notification.DEFAULT_SOUND;
notif.defaults |= Notification.DEFAULT_VIBRATE;

Intent notificationIntent = new Intent(context, TestSampleApp.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

notif.setLatestEventInfo(context, title, message, contentIntent);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
mNotificationManager.notify(1, notif);

把它放在接受推送的地方。