0

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

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生成器不工作。

回答

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); 

把它放在那里收到推送。

+0

谢谢,我已经在教程中找到它了,但我试图用其他方式使它成为 - alertdialog。 – Meryl