我目前正在构建一个涉及FCM的Android应用程序,但是我无法将所有内容整合在一起。我已经成功地将Firebase连接到我的应用程序中,并且.json文件(由我的API提供者生成)也已放置完好。如果应用程序在前台运行,则onMessagReceived会正确调用。推送通知也能正常接收,但是当在后台时点击通知事件却毫无作用。通知消失而不打开启动活动。如果我将.json文件切换为通过示例FCM应用程序生成的文件,则可以按预期方式单击通知。我不知道发生了什么。
以下是我的AndroidManifest.xml的一部分,其中包含启动器活动/ fcm服务和由我的API提供者生成的.json文件(某些数据已更改,但特定值相等):
我还包括由我的 API 供应商生成的 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引导我找到解决方案。