我想用PhoneGap的实现在Android的推送通知,我用个ebelow链接来实现GCM如何使用phonegap在状态栏中显示android的推送通知?
https://github.com/marknutter/GCM-Cordova
我能够实现推送通知,我能得到我的手机一个小样本文本提交appid regid和发件人ID后屏幕,但我想在状态栏中显示通知。任何人都可以请帮助我如何使用上面的示例在状态栏中显示推送通知。
我想用PhoneGap的实现在Android的推送通知,我用个ebelow链接来实现GCM如何使用phonegap在状态栏中显示android的推送通知?
https://github.com/marknutter/GCM-Cordova
我能够实现推送通知,我能得到我的手机一个小样本文本提交appid regid和发件人ID后屏幕,但我想在状态栏中显示通知。任何人都可以请帮助我如何使用上面的示例在状态栏中显示推送通知。
您可以使用Cordova StatusBarNotification plugin 或者如果你想有一个更快的解决方案,你可以简单地添加下面的本地Java代码到您的GCMIntentService.java的onMessage()函数:
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);
不要忘记添加以下进口,
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
务必更换YourActivityClassName.class与存根类的扩展博士的名字oidGap。例如,在示例项目中,它被称为MainActivity。
你说你已经工作了,所以编辑源代码。您收到该消息的地方会显示通知。 – Klaasvaak
@Klaasvaak呀,但写什么显示通知 –
http://developer.android.com/guide/topics/ui/notifiers/notifications.html – Klaasvaak