安卓推送通知无法打开应用程序

3
我目前正在构建一个涉及FCM的Android应用程序,但是我无法将所有内容整合在一起。我已经成功地将Firebase连接到我的应用程序中,并且.json文件(由我的API提供者生成)也已放置完好。如果应用程序在前台运行,则onMessagReceived会正确调用。推送通知也能正常接收,但是当在后台时点击通知事件却毫无作用。通知消失而不打开启动活动。如果我将.json文件切换为通过示例FCM应用程序生成的文件,则可以按预期方式单击通知。我不知道发生了什么。
以下是我的AndroidManifest.xml的一部分,其中包含启动器活动/ fcm服务和由我的API提供者生成的.json文件(某些数据已更改,但特定值相等):
<application
    android:name=".xyz"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/xyz"
    android:roundIcon="@mipmap/ic_launcher"
    android:theme="@style/Theme.xyz.Light.DarkActionBar">
    <activity
        android:name=".views.activities.SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.xyz.Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="xyz.com"
                android:pathPrefix="/api,xyz"
                android:scheme="https"/>
            <data
                android:host="xyz.pl"
                android:pathPrefix="/api,xzz"
                android:scheme="https"/>
        </intent-filter>
    </activity>

    ...

    <service android:name=".services.xyzFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <service android:name=".services.xyzFirebaseInstanceService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

    </activity>

</application>

{
  "project_info": {
    "project_number": "123456789123",
    "firebase_url": "https://xxx.firebaseio.com",
    "project_id": "xxx",
    "storage_bucket": "xxx.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:123456789123:android:a12a3456789012e1",
        "android_client_info": {
          "package_name": "com.mycompany.myapp"
        }
      },
      "oauth_client": [
        {
          "client_id": "123456789123-zzz.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "current_key"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "ads_service": {
          "status": 2
        }
      }
    }
  ],
  "configuration_version": "1"
}

我还包括由我的 API 供应商生成的 FCM 消息示例。
    [2017-11-02 12:10:06] https://fcm.googleapis.com/fcm/send
HEADERS: [
    "Authorization:key=my_auth_key"
]
DATA: {
    "notification": {
        "icon": "https://www.myavatar.com/avatar.png",
        "title": "Message title",
        "body": "aaa",
        "click_action": "https://www.app.com/notifications,open?_id=678696787lkju82"
    },
    "data": {
        "date_create": "2017-11-02 12:10:04",
        "sender_type": "user",
        "sender_app_id": "2",
        "sender_app_display": "MyApp",
        "sender_user_id": "43",
        "sender_display": "WK",
        "type": "message"
    },
    "to": "fYqHDJEVUUM:APAasdasdasdHS_GOsen-kkjghkasjhd898098klj-8797hoijo8"
}
RESPONSE: {
    "multicast_id": 556579726904--2753,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "0:1880938748%hkk4bjl2k1"
        }
    ]
}

更新

我已经找到问题所在。 "click_action"参数是导致问题的原因,我的API提供者将URL地址设置为此参数的值以在Web端上帮助自己,这就是问题所在 ;)非常感谢@Barns52引导我找到解决方案。


1
请阅读Firebase文档中有关不同消息负载的内容。FCM提供两种不同的负载。每种负载类型在应用程序处于后台时处理方式不同。 - Barns
1
在这种情况下,您需要发布用于生成消息的代码和用于接收消息的代码。仅发布“AndroidManifest”基本上无法诊断您所犯的错误。 - Barns
至少我需要看到消息是如何创建的。你在帖子中写道“ .json文件(由我的API提供商生成)”,我需要看到至少json文件的内容。 - Barns
1
我需要消息JSON。它看起来像这样: { "message":{ "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification":{ "title":"葡萄牙对丹麦", "body":"精彩比赛!" }, "data" : { "Nick" : "Mario", "Room" : "葡萄牙VSDenmark" } } } - Barns
我很高兴能够帮助你。你(!)找到了可以帮助你推动解决方案的解决方案。享受编程吧! - Barns
显示剩余6条评论
2个回答

3
我已将此内容添加到文章末尾,但它可能应该在这里:

我发现了问题。 "click_action"参数是导致问题的原因,我的API提供者将URL地址设置为该参数的值,以便在Web侧帮助自己,这就是问题所在 ;) 感谢@Barns52将我引向解决方法。


1
您必须显式调用一个活动。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接