3

Androidアプリでphonegapを介してGCMを実行するコードを正常にセットアップしました。携帯電話の登録 ID を確保し、PHP スクリプトでこの ID を使用してアプリにメッセージを送信することができました。私の唯一の問題は、アプリが開いている間にメッセージがjavascriptアラートとして表示されることです.メッセージをハンドセットに送信したいのですが、上部の通知バーにアイコンが表示されません.

**> Android デバイスのトップバーにアイコンを表示することは可能です

Phonegap 用の GCM プラグインがこれを実行できるかどうかは誰にもわかりませんか?**

C2DM-Phonegap を使用しています。 https://github.com/marknutter/GCM-コルドバ

友達を助けてください...

4

4 に答える 4

4

使用しているライブラリは、メッセージを受信したときに何をする必要があるかを指定します。コードを変更して必要なことを行うか、独自の GCMIntentService をロールすることができます。

このリンクを参照してください:

https://github.com/phonegap-build/PushPlugin

https://build.phonegap.com/plugins/324

于 2014-06-07T08:50:13.770 に答える
2

使用しているライブラリは、メッセージを受信したときに何をする必要があるかを指定します。あなたはあなたが望むことをするために彼らのコードを修正するか、あなた自身のGCMIntentServiceを転がすことができます。

于 2012-10-24T17:18:08.113 に答える
0

このコードを確認してください

private static void generateNotification(Context context、String message){ int icon = R.drawable.ic_launcher;

       // here is your icon drawable instead of ic_launcher

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context.getApplicationContext(), devicephp.class);
    // set intent so it does not start a new activity

    notificationIntent.putExtra("msg", message);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent =
            PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);


}
于 2013-01-05T09:52:30.107 に答える
0

最も簡単な方法は、次のコードを GCMIntentService.java の onMessage 関数に追加することです。使用している GCM プラグインは GCM メッセージを受信するだけですが、自分で通知をトリガーする必要があります。ステータス バー通知用の cordova プラグインを試すこともできます。

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

// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
    String message = extras.getString("message");
    String title = extras.getString("title");

    Notification notif = new Notification(R.drawable.ic_launcher, message, System.currentTimeMillis() );
    notif.flags = Notification.FLAG_AUTO_CANCEL;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.defaults |= Notification.DEFAULT_VIBRATE;

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

    notif.setLatestEventInfo(context, "Title of notification", message, contentIntent);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
    mNotificationManager.notify(1, notif);
于 2012-11-08T17:13:40.123 に答える