首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android推送通知无法打开应用程序

Android推送通知无法打开应用程序
EN

Stack Overflow用户
提问于 2017-10-26 00:20:13
回答 2查看 3.4K关注 0票数 3

我目前正在构建一个具有一些FCM使用的android应用程序。不幸的是,我不能把这一切放在一起。我已经成功地将firebase连接到我的应用程序,.json文件(由我的应用程序接口提供商生成)也放置得很好。如果app在前台,则onMessagReceived调用正确。推送通知也会正确接收,但通知时的单击事件(在后台)绝对不会执行任何操作。通知将在未打开启动活动的情况下消失。如果我将.json文件切换为我使用示例FCM应用程序生成的文件,请单击notifications works in a desired way。我不知道发生了什么。

下面我展示了我的AndroidManifest.xml的一部分,包括启动器活动/fcm服务和由我的api提供者生成的.json文件(一些数据被更改了,但特定的值是相等的):

代码语言:javascript
复制
<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>

代码语言:javascript
复制
{
  "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消息。

代码语言:javascript
复制
    [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给我提供解决方案。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-20 20:44:41

我在一篇文章的末尾添加了这句话,但它可能应该是这样的:

我找到了问题所在。"click_action“参数导致了问题,我的api提供商将url地址设置为此参数的值,以便在web端帮助自己,仅此而已;)非常感谢@Barns52给我提供解决方案。

票数 1
EN

Stack Overflow用户

发布于 2017-10-26 00:38:26

你必须显式地调用一个活动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46937447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档