Cordoba fcm plugin on Android data.wasTapped does not work

I am trying to use the cordova fcm plugin on Android to implement the data sent by Firebase Cloud Messaging. I have successfully received notifications, but when I click them, they do not give the warning I want.

Here is the code used in 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);
            }
        );
    },

And here is the php code that I used to send the notification:

    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, , , . - , , , , , , , URL- inAppBrowser, .

+4
1

"cordova-plugin-fcm" click_action FCM_PLUGIN_ACTIVITY .

:

{
  "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
}
+9

Source: https://habr.com/ru/post/1653165/


All Articles