【问题标题】:Show alert with message after push received. Phonegap收到推送后显示带有消息的警报。电话间隙
【发布时间】:2013-04-02 04:21:23
【问题描述】:

我正在使用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不起作用。

【问题讨论】:

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


    【解决方案1】:

    您可以使用此代码在收到推送后显示警报:

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

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

    【讨论】:

    • 谢谢,我已经在教程中找到了它,但我正在尝试以其他方式制作它 - alertdialog。
    猜你喜欢
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    相关资源
    最近更新 更多