
[英]Display push notification as alert message on iOS app [phonegap/cordova][Pushwoosh]
[英]Show alert with message after push received. Phonegap
我正在使用GitHub-GCM Cordova插件 。 我的问题是我收到推送消息后无法显示。
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无法正常工作。
您可以使用以下代码在收到推送后显示警报:
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);
将其放置在收到推动的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.