2016-04-25 18 views
3

私はPush Pluginを使用しました。私はアクションボタン付きのプッシュを送信しています。1)受け入れる2)無視してください。コルドバAndroidのプッシュ通知アクションボタン

通知が届いたときに「承諾」ボタンをクリックしました。私は "受け入れ"ボタンのコールバックでパラメータが欲しいです。それから私は通知の "承諾"と呼ばれると識別します。コード "app.onPushAccept" 機能で

コード参照

//initialization of push object 
     var push = PushNotification.init({ 
      "android": { 
       "alert": "true", 
       "senderID": CONFIG.PROJECT_NUMBER, 
       "icon": "img/ionic.png", 
       "iconColor": "blue", 
       "badge": "true" 
      }, 
      "ios": { 
       "alert": "true", 
       "badge": "true", 
       "sound": "true" 
      }, 
      "windows": { 

      } 
     }); 

     //listner for getting registration detail of device 
     push.on('registration', function(data) { 
      device_id_for_push=data.registrationId; 
     }); 

     //listner called on new push notification 
     push.on('notification', function(data) { 
      // app.onPushAccept(data); 
      alert("on notification"); 
      alert(JSON.stringify(data)); 
     }); 

     //error listner 
     push.on('error', function(e) { 
      // alert(e); 
      // alert("push error"); 
     }); 

     app.onPushAccept=function(data){ 
      alert("onPushAccept") 
      alert(JSON.stringify(data)); 
      // cordova.plugins.notification.badge.clear(); 
      // cordova.plugins.notification.badge.increase(); 
     } 

は、ボタンを "受け入れる" のコールバック..です

できるだけ早く私を助けてください。 は...

答えて

2

Androidのプッシュ通知(のみ)

ステップ1 - オープンGCMIntentService.javaファイル - まず第一に、指定したディレクトリ以下

 plugins > phonegap-plugin-push > src > android > com > adobe > phonegap > push 

ステップ2に進みます上のディレクトリから

ステップ3 - ... "createActions" と 実際のパラメータを追加 "requestCodeを" などの関数呼び出しを決定

 createActions(extras,mBuilder,resources,packageName,notId,requestCode); 

ステップ4 - 関数定義を決定する "createActions" と のような正式なパラメータ "int型のrequestCode" を追加します。.. 。

 private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId,int requestCode) 

ステップ5 - "createActions" 関数の定義で内部ループのは

 pIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

    pIntent = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

ステップ6 ... "私" を "requestCode" などから二番目のパラメータを変更し - 上記のすべて完了したらステップは、すでにプラットフォームが追加されている場合はアンドロイドプラットフォームを削除してからアンドロイドプラットフォームを追加します。

私の解決方法で間違いが見つかった場合は、申し訳ありませんが改善します。

{ 
    "registration_ids": ["my device id"], 
    "data": { 
     "title": "My title", 
     "message": "My message.", 
     "actions": [ 
      { "title": "Accept", "callback": "app.accept", "foreground": true}, 
      { "title": "Ignore", "callback": "app.ignore", "foreground": false} 
     ] 
    } 
} 

とセットアップ以下のアクションボタンハンドラを持っている:

+0

ありがとう、このソリューションは本当に働いていた.. –

0

使用プラグインのnavigator.notification.confirm方法cordova-plugin-dialogs

それはカスタマイズの確認ダイアログボックスが表示されますありがとうございました。

構文

navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels]) 
  • メッセージ:ダイアログメッセージ。 (String)
  • confirmCallback:ボタンが押された(1、2、または3)インデックスで呼び出されるコールバック、またはボタンが押されずにダイアログが閉じられたときにコールバック(0)。 (機能)
  • タイトル:ダイアログタイトル。 (文字列)(オプション、デフォルトはConfirm)
  • buttonLabels:ボタンラベルを指定する文字列の配列。 (アレイ)([OK、キャンセル]オプション、デフォルト)

あなたはあなたのニーズを満たすために を[ "無視"、 "同意する"]にbuttonLabelsを変更することができます。

function onConfirm(buttonIndex) { 
    alert('You selected button ' + buttonIndex); 
} 

navigator.notification.confirm(
    'You are the winner!', // message 
    onConfirm,   // callback to invoke with index of button pressed 
    'Game Over',   // title 
    ['Accept','Ignore']  // buttonLabels 
); 
+0

私は「受け入れる」ボタンをクリックしたことを確認しました。しかし、私はサーバーから私のコールバックに "受け入れる"ボタンのパラメータを渡したいと思います。 –

+0

@EjazMafatあなたはサーバーからコールバックに渡すことはできません、私はそれらのパラメータを得るために$ .getまたは$ .ajaxを使ってサーバーコールを行うべきだと思いますあなたはそれを渡すことができます。 –

1

さて、まずあなたは、次のペイロードを送信していると想像

app.accept = function(data} { 
    // do something 
} 

app.ignore = function(data} { 
    // do something 
} 

は今、あなたはどちらか何かを置くことができる2つのオプションがあります受け取ったプッシュを一意に識別するプッシュペイロードにdata.additionalDataに格納されるか、またはコールバックを変更して別のイベントハンドラを呼び出すように変更します。

app.accept = function(data} { 
    app.processPush('accept', data); 
} 

app.ignore = function(data} { 
    app.processPush('ignore', data); 
} 

app.processPush = function(type, data) { 
    if (type === 'accept') { 
    // do accept stuff 
    } else if (type === 'ignore') { 
    // do ignore stuff 
    } 
} 
関連する問題