HMS-Core / hms-cordova-plugin

This repo contains all of Cordova HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
88 stars 40 forks source link

cordova-plugin-hms-push onNotificationOpenedApp call without result data #139

Open victor-sanchez-ccc opened 9 months ago

victor-sanchez-ccc commented 9 months ago

Description I trying to capture push notification content, but the onNotificationOpenedApp is triggering when i tap on a push and my app oppen but the result data comes in empty object. the plugin works correctly for receive push notification, but not works for get the push info data or text to my app.

Expected behavior result data comes with push info to be capture inside my app, when onNotificationOpenedApp event is fire, as show in documentation

onNotificationOpenedApp(callback)

Current behavior result comes in empty object when app opened by touching a push notification

Logs

Logs from log inspector android studio running my app

I/HMSSDK_PendingResultImpl: init uri:push.gettoken I/HmsPushInstanceId: HMSPush plugin initialized I/HMSSDK_PendingResultImpl: setResultCallback I/HMSSDK_HmsMessaging: invoke turnOnPush I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/chromium: [INFO:CONSOLE(15)] "NOTIFICATION_OPENED_EVENT {}", source: https://localhost/dist/bundle.js (15) <-- console log from app js I/HMSSDK_HmsMessaging: turn on/off with AIDL I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/HMSSDK_HuaweiApi: No setInnerHms, hms pkg name is com.huawei.hwid I/HMSSDK_HuaweiApi: sendRequest D/HMSLogger: singleEventMap -> {apiName=getInitialNotification, package=com.ccc.app, cpAppVersion=2.6.6.1, version=6.3.0.304, platform=Cordova, result=0, costTime=0, service=Cross-Platform, kit=Push, appid=101754691, model=flame, networkType=WIFI, callTime=1691190441506} I/HMSSDK_HMSPackageManager: Enter getHMSPackageName I/HMSSDK_HuaweiApi: isConnected:true. I/HMSSDK_BaseHmsClient: getAdapter:isInner:false, mInnerBinderAdapter:null, mOuterBinderAdapter:com.huawei.hms.adapter.OuterBinderAdapter@40ebfca I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/HMSSDK_RequestManager: addToConnectedReqMap I/HMSSDK_HmsClient: post msg api_name:push.setNotifyFlag, app_id:101754691|, pkg_name:com.ccc.app, sdk_version:60800300, session_id:, transaction_id:101754691fyFlag20230804170721476343145, kitSdkVersion:60900300, apiLevel:1 I/HMSSDK_BaseAdapter: In constructor, activityWeakReference is java.lang.ref.WeakReference@83141fb, activity is com.ccc.app.MainActivity@3599851 I/HMSSDK_BaseAdapter: in baseRequest + uri is :push.setNotifyFlag, transactionId is : 101754691fyFlag20230804170721476343145 W/Parcel: Expecting binder but got null! I/HMSSDK_PendingResultImpl: init uri:push.setNotifyFlag I/HMSSDK_PendingResultImpl: setResultCallback I/HMSSDK_PendingResultImpl: setResult:0 I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/HMSSDK_BaseAdapter: api is: push.setNotifyFlag, resolution: null, status_code: 0 I/HMSSDK_HuaweiApi: No setInnerHms, hms pkg name is com.huawei.hwid I/HMSSDK_BaseAdapter: baseCallBack.onComplete I/HMSSDK_HMSPackageManager: Enter getHMSPackageNameForMultiService I/HMSSDK_HuaweiApi: sendRequest I/HMSSDK_HmsClient: receive msg status_code:0, error_code:0, api_name:push.setNotifyFlag, app_id:101754691|, pkg_name:com.ccc.app, session_id:, transaction_id:101754691fyFlag20230804170721476343145, resolution:null I/HMSSDK_HMSPackageManager: Enter getHMSPackageName I/HMSSDK_TaskApiCall: doExecute, uri:push.setNotifyFlag, errorCode:0, transactionId:101754691fyFlag20230804170721476343145 I/HMSSDK_HuaweiApi: isConnected:true. I/HMSSDK_BaseVoidTask: Operate succeed

Environment

Other

Code inside my app in JavaScript

const initHuaweiPush = (props) => { //works
  HmsPush.init()

  HmsPush.turnOnPush()//works
    .then((result) => console.log("turnOnPush", result))
    .catch((error) => console.log("turnOnPush", error))

  HmsPush.getToken()//works
    .then((result) => {
      console.log("getToken", result)
      setRegistrationId(props, result)
    })
    .catch((error) => {
      console.log("getErrorToken", error)
    })

  HmsPushEvent.onNotificationOpenedApp((result) => {// doesn't work
    console.log("NOTIFICATION_OPENED_EVENT", JSON.stringify(result));
    const remoteMessageData = result.remoteMessage;
    const extrasData = result.extras;
    const uriPage = result.uriPage;

    alert("NOTIFICATION_OPENED_EVENT")
    alert(JSON.stringify(result))
    alert(remoteMessageData)
    alert(extrasData)
    alert(uriPage)
  })

  HmsPushEvent.onRemoteMessageReceived((result) => {// doesn't work
    const CordovaRemoteMessageObj = new HmsPush.CordovaRemoteMessage(result.msg);
    const msg = CordovaRemoteMessageObj.parseMsgAllAttribute(result.msg);
    console.log("Data message received : " + msg);
    alert('data message received')
    alert(JSON.stringify())
  })

}

Push payload send in postman

{
    //"validate_only": false,
    "message": 
    {
        "data": "{'param1':'value1','param2':'value2'}",
        "notification":
        {
            "title": "Huawei Push Kit",
            "body": "Hello, I'm a Push Kit."
        },
        "android":
        {
            "collapse_key": -1,
            "notification":
            {
                "icon": "notification_icon",
                "notify_id": 41186,
                "foreground_show": false, --> try with this on and off same result
                "badge": {
                   "add_num": 1,
                   "class": "com.ccc.app.MainActivity"
                },
                "click_action":
                {
                    "type": 3 ,//open app in tap,
                    "action":"com.ccc.app.MainActivity"
                }
            },

            "priority":"high",
            "delayWhileIdle":false
        },
        "token": ["KAAAAACy0xX3AAC4yG4Oun3XYVPW7Id8SC6Rd0MIcF6rKXWocHHzQg6LzJXXxySWu6Tifgr1Sxo2CMT49zK9RyeME4IOvE3E2uhztPaHUFhSTyJhrw"]
    }
}