Android数据上的cordova fcm插件.wasTapped无效

前端之家收集整理的这篇文章主要介绍了Android数据上的cordova fcm插件.wasTapped无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在 Android上使用cordova fcm插件来实现Firebase Cloud Messaging发送的数据.我成功收到了通知,但是当我点击它们时,它们没有发出我想要的警报.

这是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,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插件未完全禁用.
我想在点击通知时启动网址,但是现在看来我甚至无法使用这些数据.如果有人知道如何解决这个问题,请告诉我,请告诉我如何使用字符串化数据在cordova inAppBrowser中启动网址,谢谢.

解决方法

对于“cordova-plugin-fcm”插件,您需要在通知有效负载部分中将click_action设置为FCM_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
}
原文链接:https://www.f2er.com/android/309947.html

猜你在找的Android相关文章