4

Androidでcordova fcmプラグインを使用してFirebase Cloud Messagingから送信されたデータを実装しようとしています。私は正常に通知を受けましたが、私がそれらをタップするとき、彼らは私が欲しいアラートを与えていません。Android data.wasでコードバfcmプラグインが動作していません

ここでindex.jsで使用されるコードです:

onDeviceReady: function() { 
     app.receivedEvent('deviceready'); 
     FCMPlugin.onNotification(
      function(data){ 
       if(data.wasTapped){ 
        //Notification was received on device tray and tapped by the user. 
        alert(JSON.stringify(data)); 
       }else{ 
        //Notification was received in foreground. Maybe the user needs to be notified. 
        alert(JSON.stringify(data)); 
       } 
      }, 
      function(msg){ 
       alert('onNotification callback successfully registered: ' + msg); 
      }, 
      function(err){ 
       alert('Error registering onNotification callback: ' + err); 
      } 
     ); 
    }, 

そして、ここでは、私は、通知を送信するために使用されるPHPコードです:

function pushAndroidNotification ($productUrl, $message, $deviceToken) { 
     $url = 'https://fcm.googleapis.com/fcm/send'; 

     $fields = array(
      'registration_ids' => array($deviceToken), 
      'notification' => array(
       "title" => "rBUX", 
       "body" => $message, 
       "icon" => "name_of_icon"), 
      'data' => array("url" => $productUrl) 
     ); 
     $jfields = json_encode($fields); 
     echo "\r\n<br>Post json:".$jfields; 

     $headers = array(
      'Authorization: key = AIzaSyBPRoJ7zgmevPYIzoDweVgNTbmsPBW5ofo', 
      'Content-Type: application/json' 
     ); 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $jfields); 
     $result = curl_exec($ch); 
     if ($result === FALSE) { 
      echo "\r\n<br>Notify Failed:".curl_error($ch); 
      die('Curl failed: '.curl_error($ch)); 
     }else{ 
      echo "\r\n<br>Notify passed:".$result; 
     } 
     $jresponse = json_decode($result, true); 

     curl_close($ch); 

     return $jresponse; 
    } 

しかし、私はアプリを起動するたびに、私は「onNotificationコールバックが正常に登録されました:OK」というアラートが表示されるため、FCMプラグインは完全に無効になっていません。 通知をタップするとurlを起動したいのですが、今のところデータを使用することさえできないようです。誰かがこれを解決する方法を知っていれば私に教えてください、コード化されたデータを使用して、コードブラウザのinAppBrowserでURL​​を起動する方法を教えてください、ありがとうございます。

答えて

8

"cordova-plugin-fcm"プラグインの場合、通知ペイロード部分にclick_actionFCM_PLUGIN_ACTIVITYを設定する必要があります。

私は彼らのwebsiteから以下を得た:

{ 
    "notification":{ 
    "title":"Notification title", //Any value 
    "body":"Notification body", //Any value 
    "sound":"default", //If you want notification sound 
    "click_action":"FCM_PLUGIN_ACTIVITY", //Must be present for Android 
    "icon":"fcm_push_icon" //White icon Android resource 
    }, 
    "data":{ 
    "param1":"value1", //Any data to be retrieved in the notification callback 
    "param2":"value2" 
    }, 
    "to":"/topics/topicExample", //Topic or single device 
    "priority":"high", //If not set, notification won't be delivered on completely closed iOS app 
    "restricted_package_name":"" //Optional. Set for application filtering 
} 
+0

は作業それを手に入れました! 'curl --header"認証:key = YOUR_API_KEY " - ヘッダコンテンツタイプ:" application/json "https://fcm.googleapis.com/fcm/send -d" {\ " \ "テキスト\":\ "サンプルメッセージ\"、\ "click_action \":\ ":\"あなたのトークン/ \ "FCM_PLUGIN_ACTIVITY \"}} "" –

+0

+1これは動作します。アプリ内イベントを正常に取得しましたが、ステータスバーから通知をクリックしても、click_actionパラメータを追加するまでイベントは発生しませんでした。 –

+0

私はそれを見逃したか分かりません、あなたは私に多くの助け、感謝 –

関連する問題