@tencentcloud/sdk-mcp 1.7.3 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +22 -23
- package/knowledge/path-meta.js +23 -1
- package/package.json +1 -1
- package/resource/index/manifest.json +1 -1
- package/resource/integration/callkit/preset/android/integration.md +4 -0
- package/resource/integration/callkit/preset/flutter/integration.md +8 -4
- package/resource/integration/callkit/preset/ios/integration.md +16 -15
- package/resource/integration/callkit/preset/react/integration.md +2 -2
- package/resource/integration/callkit/preset/vue/integration.md +9 -12
- package/resource/integration/chat/preset/android/integration.md +5 -147
- package/resource/integration/chat/preset/flutter/integration.md +22 -130
- package/resource/integration/chat/preset/ios/integration.md +12 -279
- package/resource/integration/chat/preset/react/integration.md +27 -1
- package/resource/integration/chat/preset/uni-app/integration.md +5 -1
- package/resource/integration/chat/preset/vue/integration.md +21 -31
- package/resource/integration/livekit/preset/live/android/live-host-integration.md +4 -0
- package/resource/integration/livekit/preset/live/ios/live-host-integration.md +4 -0
- package/resource/integration/livekit/preset/live/ios/prepare-integration.md +3 -3
- package/resource/integration/livekit/preset/live/vue/live-list-integration.md +3 -4
- package/resource/integration/livekit/preset/live/vue/live-player-desk-integration.md +0 -1
- package/resource/integration/livekit/preset/live/vue/live-player-h5-integration.md +0 -1
- package/resource/integration/livekit/preset/live/vue/live-pusher-integration.md +4 -9
- package/resource/integration/roomkit/preset/vue/integration.md +152 -652
- package/resource/knowledge/callkit/best-practice/android/video-chat-dating.md +490 -0
- package/resource/knowledge/callkit/best-practice/flutter/android-keep-call-alive-background.md +79 -0
- package/resource/knowledge/callkit/best-practice/flutter/background-incoming-call-no-notification.md +99 -0
- package/resource/knowledge/callkit/best-practice/flutter/ios-keep-call-alive-background.md +93 -0
- package/resource/knowledge/callkit/best-practice/flutter/ios-startup-crash-version-voip.md +68 -0
- package/resource/knowledge/callkit/core-sdk/android/answer-call.md +2 -2
- package/resource/knowledge/callkit/core-sdk/android/make-call.md +5 -5
- package/resource/knowledge/callkit/core-sdk/flutter/answer-call.md +7 -7
- package/resource/knowledge/callkit/core-sdk/flutter/make-call.md +10 -10
- package/resource/knowledge/callkit/core-sdk/flutter/offline-push.md +1 -1
- package/resource/knowledge/callkit/core-sdk/ios/answer-call.md +18 -16
- package/resource/knowledge/callkit/core-sdk/ios/make-call.md +16 -14
- package/resource/knowledge/callkit/core-sdk/miniprogram/call-engine.md +19 -19
- package/resource/knowledge/callkit/core-sdk/miniprogram/call-event.md +16 -16
- package/resource/knowledge/callkit/core-sdk/uni-app/answer-call.md +2 -86
- package/resource/knowledge/callkit/core-sdk/uni-app/make-call.md +2 -104
- package/resource/knowledge/callkit/core-sdk/web/call-event.md +2 -2
- package/resource/knowledge/callkit/faq/android.md +4 -4
- package/resource/knowledge/callkit/faq/common.md +4 -4
- package/resource/knowledge/callkit/faq/error-code.md +62 -36
- package/resource/knowledge/callkit/faq/uniapp-miniprogram.md +1 -1
- package/resource/knowledge/callkit/preset/android/api.md +10 -10
- package/resource/knowledge/callkit/preset/harmonyos/api.md +362 -0
- package/resource/knowledge/callkit/preset/harmonyos/integration.md +322 -0
- package/resource/knowledge/callkit/preset/ios/api.md +9 -9
- package/resource/knowledge/callkit/preset/miniprogram/api-uniapp.md +293 -0
- package/resource/knowledge/callkit/preset/miniprogram/api.md +19 -19
- package/resource/knowledge/callkit/preset/miniprogram/integration.md +292 -0
- package/resource/knowledge/callkit/preset/miniprogram/uniapp-integration.md +521 -0
- package/resource/knowledge/callkit/preset/uni-app/api.md +49 -0
- package/resource/knowledge/callkit/preset/uni-app/integration.md +353 -0
- package/resource/knowledge/chat/preset/android-view/integration.md +54 -102
- package/resource/knowledge/chat/preset/ios/features/language.md +5 -5
- package/resource/knowledge/chat/preset/ios-uikit/integration.md +194 -926
- package/resource/knowledge/chat/preset/react/features/search.md +9 -214
- package/resource/knowledge/chat/preset/react/h5/integration.md +965 -0
- package/resource/knowledge/chat/preset/vue/features/chat-header.md +0 -36
- package/resource/knowledge/chat/preset/vue/features/contact-list.md +0 -34
- package/resource/knowledge/chat/preset/vue/features/conversation-list.md +0 -39
- package/resource/knowledge/chat/preset/vue/features/conversation-preview.md +0 -74
- package/resource/knowledge/chat/preset/vue/features/message-input.md +4 -4
- package/resource/knowledge/chat/preset/vue/features/search.md +9 -790
- package/resource/knowledge/chat/preset/vue/h5/integration.md +724 -0
- package/resource/knowledge/livekit/core-sdk/features/android/audience-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/android/live-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/flutter/audience-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/flutter/live-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/ios/audience-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/ios/live-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/uni-app/audience-list.md +3 -3
- package/resource/knowledge/livekit/core-sdk/features/uni-app/live-list.md +3 -170
- package/resource/knowledge/livekit/core-sdk/live/android/co-guest-interaction.md +1 -1
- package/resource/knowledge/livekit/core-sdk/live/android/host-interaction.md +3 -3
- package/resource/knowledge/livekit/core-sdk/live/flutter/co-guest-interaction.md +1 -1
- package/resource/knowledge/livekit/core-sdk/live/flutter/host-interaction.md +3 -3
- package/resource/knowledge/livekit/core-sdk/live/flutter/integration.md +3 -3
- package/resource/knowledge/livekit/core-sdk/live/ios/co-guest-interaction.md +1 -1
- package/resource/knowledge/livekit/core-sdk/live/ios/host-interaction.md +3 -3
- package/resource/knowledge/livekit/core-sdk/live/ios/integration.md +2 -2
- package/resource/knowledge/livekit/core-sdk/live/uni-app/co-guest-interaction.md +13 -78
- package/resource/knowledge/livekit/core-sdk/live/uni-app/host-interaction.md +5 -70
- package/resource/knowledge/livekit/core-sdk/live/uni-app/integration.md +10 -10
- package/resource/knowledge/livekit/core-sdk/voice/android/co-guest-interaction.md +1 -1
- package/resource/knowledge/livekit/core-sdk/voice/android/host-interaction.md +4 -4
- package/resource/knowledge/livekit/core-sdk/voice/flutter/co-guest-interaction.md +1 -1
- package/resource/knowledge/livekit/core-sdk/voice/ios/co-guest-interaction.md +1 -1
- package/resource/knowledge/livekit/core-sdk/voice/ios/host-interaction.md +4 -4
- package/resource/knowledge/livekit/core-sdk/voice/uni-app/integration.md +7 -7
- package/resource/knowledge/livekit/preset/live/vue/features/barrage.md +1 -24
- package/resource/knowledge/livekit/preset/live/vue/features/live-audience-list.md +0 -3
- package/resource/knowledge/livekit/preset/live/vue/features/live-view.md +0 -5
- package/resource/knowledge/push/api-reference/harmonyos.md +9 -9
- package/resource/knowledge/push/api-reference/unity.md +10 -10
- package/resource/knowledge/push/api-reference/unreal-engine.md +11 -11
- package/resource/knowledge/push/config/donut.md +3 -3
- package/resource/knowledge/push/config/harmonyos.md +12 -12
- package/resource/knowledge/push/config/ios.md +2 -2
- package/resource/knowledge/push/integration/android.md +90 -1067
- package/resource/knowledge/push/integration/donut.md +11 -11
- package/resource/knowledge/push/integration/flutter.md +38 -24
- package/resource/knowledge/push/integration/harmonyos.md +1 -11
- package/resource/knowledge/push/integration/ios.md +29 -40
- package/resource/knowledge/push/integration/react-native.md +1 -1
- package/resource/knowledge/push/integration/uni-app.md +1 -1
- package/resource/knowledge/push/integration/unity.md +4 -4
- package/resource/knowledge/push/integration/unreal-engine.md +9 -9
- package/resource/knowledge/roomkit/core-sdk/android/room-state.md +6 -6
- package/resource/knowledge/roomkit/core-sdk/android/schedule-room.md +13 -13
- package/resource/knowledge/roomkit/core-sdk/flutter/room-state.md +5 -5
- package/resource/knowledge/roomkit/core-sdk/flutter/schedule-room.md +4 -4
- package/resource/knowledge/roomkit/core-sdk/ios/room-state.md +6 -6
- package/resource/knowledge/roomkit/core-sdk/ios/schedule-room.md +4 -4
- package/resource/knowledge/roomkit/core-sdk/vue/device-detection.md +0 -9
- package/resource/knowledge/roomkit/core-sdk/vue/free-beauty-panel.md +0 -9
- package/resource/knowledge/roomkit/core-sdk/vue/recording.md +3 -3
- package/resource/knowledge/roomkit/core-sdk/vue/room-chat.md +0 -3
- package/resource/knowledge/roomkit/core-sdk/vue/room-view.md +0 -16
- package/resource/knowledge/roomkit/core-sdk/vue/schedule-room.md +0 -3
- package/resource/knowledge/roomkit/core-sdk/vue/virtual-background.md +3 -6
- package/resource/knowledge/roomkit/core-sdk/vue/whiteboard-annotation.md +0 -15
- package/resource/knowledge/roomkit/preset/android/integration.md +5 -202
- package/resource/knowledge/roomkit/preset/flutter/integration.md +17 -13
- package/resource/knowledge/roomkit/preset/harmonyos/integration.md +10 -2
- package/resource/knowledge/roomkit/preset/ios/integration.md +7 -204
- package/resource/knowledge/roomkit/preset/react/integration.md +0 -202
- package/resource/knowledge/roomkit/preset/uniapp-app/integration.md +244 -500
- package/resource/knowledge/rtcengine/web/plugin/42-advanced-realtime-transcriber.md +25 -6
- package/server.js +1 -1
- package/utils/preflight-route.js +203 -185
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
|
@@ -2,276 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
## 前提条件
|
|
4
4
|
|
|
5
|
-
请确认已 开通 Push 服务 并按需完成 **Android 厂商配置**(小米 / 华为 / OPPO / vivo / 荣耀 / 魅族 / Google FCM
|
|
5
|
+
请确认已 开通 Push 服务 并按需完成 **Android 厂商配置**(小米 / 华为 / OPPO / vivo / 荣耀 / 魅族 / Google FCM)。
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|---------|---------|---------|
|
|
9
|
-
|`SDKAppID`|腾讯云控制台 > **推送服务 Push** > **概览**|调用 `registerPush` 注册推送服务。|
|
|
10
|
-
|客户端密钥|腾讯云控制台 > **推送服务 Push** > **概览** > **客户端密钥**|调用 `registerPush` 注册推送服务。Push 的客户端密钥和 Chat 的客户端密钥不同,请勿混用。|
|
|
11
|
-
|`timpush-configs.json`|腾讯云控制台下载|放入 Android 应用模块的 `assets` 目录,TIMPush 注册时会读取该配置文件。|
|
|
12
|
-
|Android 工程包名|Android 工程 `applicationId`|需要与厂商平台应用包名保持一致。|
|
|
13
|
-
|目标厂商配置|对应厂商配置文档|确认厂商侧已开通推送服务,并已在腾讯云控制台添加厂商证书。|
|
|
14
|
-
|厂商配置文件|厂商开放平台|华为、荣耀、Google FCM 需要将对应 JSON 配置文件添加到工程中。|
|
|
15
|
-
|测试真机|目标厂商设备|厂商通道建议使用对应厂商真机验证。设备厂商与配置厂商不一致时,验证结果可能误导。|
|
|
16
|
-
|TIMPush 版本号 `VERSION`|更新日志|Gradle 依赖版本。本文使用 `VERSION` 占位,请替换为实际版本号。建议使用最新版本;如使用 7.7.5283 以下版本,荣耀通道配置可能有差异。|
|
|
17
|
-
|
|
18
|
-
本文示例中的 `VERSION`、`SDKAppID`、`AppKey`、厂商 AppID、厂商 AppKey 均为占位符,请勿在代码仓库中提交真实密钥。
|
|
19
|
-
|
|
20
|
-
## AI 集成
|
|
7
|
+
## 方式1:AI 集成
|
|
21
8
|
|
|
22
9
|
通过 npx 安装 [@tencent-rtc/trtc-push-skill](https://www.npmjs.com/package/@tencent-rtc/trtc-push-skill/v/1.0.1#%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) 到本地 AI IDE 中,辅助完成 TIMPush 离线推送集成。安装后,您可以直接向 AI 输入“集成 Android 离线推送”等需求,AI 将根据项目类型引导您完成环境检测、厂商通道配置、凭据填写、代码接入和验证等步骤。详情可参考 AI Coding。
|
|
23
10
|
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
### 步骤1:集成 TIMPush SDK
|
|
27
|
-
|
|
28
|
-
#### 下载并添加 TIMPush 配置文件
|
|
29
|
-
|
|
30
|
-
下载后,将该文件添加到应用模块的 `assets` 目录。推荐存储路径:`app/src/main/assets/timpush-configs.json`,其中 app 是您项目的应用模块,可替换成实际名称。如果工程中没有 `assets` 目录,请在 `src/main/` 下手动创建。
|
|
31
|
-
|
|
32
|
-
> **注意:**
|
|
33
|
-
> TIMPush 注册推送时会读取该文件中的厂商证书配置,不要放在 MainActivity 同级目录、工程根目录或 res 目录。如果文件缺失或放错目录,SDK 无法获得对应厂商通道配置,可能导致注册或收消息失败。
|
|
34
|
-
>
|
|
35
|
-
|
|
36
|
-
#### 配置 Gradle 仓库
|
|
37
|
-
|
|
38
|
-
配置仓库的目的是让 Gradle 能下载 TIMPush 及相关依赖。本节只配置与厂商无关的公共仓库:`google()`、`mavenCentral()` 用于解析 Android 官方组件,腾讯云 Maven 仓库用于解析 TIMPush 等腾讯云依赖。华为、荣耀的厂商 Maven 仓库请在「厂商通道集成」对应厂商 Tab 中追加。
|
|
11
|
+
## 方式2:手动集成
|
|
39
12
|
|
|
40
|
-
|
|
13
|
+
您可下载 [Push 接入脚本工具](https://sdk-im-1252463788.cos.ap-hongkong.myqcloud.com/tools/push_script_tool/1.0.1/timpush-integrate-1.0.1.zip),自动将推送构建配置写入你的 Android 工程,替代手工逐项修改,支持预览与自动备份。详细使用方法见包内说明文档。
|
|
41
14
|
|
|
42
|
-
|
|
43
|
-
|---------|---------|
|
|
44
|
-
|`settings.gradle`、`build.gradle`|Groovy DSL|
|
|
45
|
-
|`settings.gradle.kts`、`build.gradle.kts`|Kotlin DSL|
|
|
15
|
+
### 步骤1:下载并添加 timpush-configs 配置文件
|
|
46
16
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
> **注意:**
|
|
50
|
-
> 不要把 Groovy 示例直接复制到 `.kts` 文件中。Kotlin DSL 使用双引号、括号和 `uri(...)` 写法。
|
|
51
|
-
>
|
|
52
|
-
|
|
53
|
-
【Gradle 7.1 及以上版本】
|
|
54
|
-
|
|
55
|
-
在项目级 `settings.gradle`(Groovy DSL)或 `settings.gradle.kts`(Kotlin DSL)中,同时在 `pluginManagement > repositories` 和 `dependencyResolutionManagement > repositories` 中添加仓库。
|
|
56
|
-
|
|
57
|
-
【Groovy DSL (settings.gradle)】
|
|
58
|
-
``` java
|
|
59
|
-
pluginManagement {
|
|
60
|
-
repositories {
|
|
61
|
-
gradlePluginPortal()
|
|
62
|
-
google()
|
|
63
|
-
mavenCentral()
|
|
64
|
-
maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
|
|
65
|
-
}
|
|
66
|
-
}
|
|
17
|
+
按需完成厂商后台、腾讯云控制台配置后,在腾讯云控制台下载 `timpush-configs.json`,并将其放置在应用的 `assets` 目录下。下载路径为:控制台 > **推送服务 Push** > **推送设置** > **厂商配置** > **下载证书**:
|
|
67
18
|
|
|
68
|
-
|
|
69
|
-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
70
|
-
repositories {
|
|
71
|
-
google()
|
|
72
|
-
mavenCentral()
|
|
73
|
-
maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
19
|
+
### 步骤2:集成 TIMPush SDK
|
|
77
20
|
|
|
78
|
-
|
|
21
|
+
在应用模块的 `build.gradle` 的 dependencies 中添加 TIMPush SDK。
|
|
79
22
|
``` java
|
|
80
|
-
pluginManagement {
|
|
81
|
-
repositories {
|
|
82
|
-
gradlePluginPortal()
|
|
83
|
-
google()
|
|
84
|
-
mavenCentral()
|
|
85
|
-
maven { url = uri("https://mirrors.tencent.com/nexus/repository/maven-public/") }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
dependencyResolutionManagement {
|
|
90
|
-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
91
|
-
repositories {
|
|
92
|
-
google()
|
|
93
|
-
mavenCentral()
|
|
94
|
-
maven { url = uri("https://mirrors.tencent.com/nexus/repository/maven-public/") }
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
【Gradle 7.0 版本】
|
|
100
|
-
|
|
101
|
-
Gradle 7.0 版本通常使用 Groovy DSL。如您的工程使用 Kotlin DSL,请将单引号改为双引号,`url "..."` 改为 `url = uri("...")`。
|
|
102
|
-
1. 在项目级 `build.gradle` 的 `buildscript > repositories` 中添加插件仓库。华为、荣耀、Google FCM 的插件 classpath 请在「厂商通道集成」对应厂商 Tab 中追加。
|
|
103
|
-
|
|
104
|
-
``` groovy
|
|
105
|
-
buildscript {
|
|
106
|
-
repositories {
|
|
107
|
-
google()
|
|
108
|
-
mavenCentral()
|
|
109
|
-
maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
2. 在 `settings.gradle` 的 `dependencyResolutionManagement > repositories` 中添加依赖仓库。
|
|
114
|
-
|
|
115
|
-
``` groovy
|
|
116
|
-
dependencyResolutionManagement {
|
|
117
|
-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
|
118
|
-
repositories {
|
|
119
|
-
google()
|
|
120
|
-
mavenCentral()
|
|
121
|
-
maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
【Gradle 7.0 以下版本】
|
|
127
|
-
|
|
128
|
-
Gradle 7.0 以下版本通常使用 Groovy DSL。如您的工程使用 Kotlin DSL,请将单引号改为双引号,`url "..."` 改为 `url = uri("...")`。
|
|
129
|
-
|
|
130
|
-
在项目级 `build.gradle` 的 `buildscript > repositories` 和 `allprojects > repositories` 中添加仓库。华为、荣耀、Google FCM 的插件 classpath 请在「厂商通道集成」对应厂商 Tab 中追加。
|
|
131
|
-
``` groovy
|
|
132
|
-
buildscript {
|
|
133
|
-
repositories {
|
|
134
|
-
google()
|
|
135
|
-
mavenCentral()
|
|
136
|
-
maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
allprojects {
|
|
141
|
-
repositories {
|
|
142
|
-
google()
|
|
143
|
-
mavenCentral()
|
|
144
|
-
maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
#### 集成 TIMPush 基础依赖
|
|
150
|
-
|
|
151
|
-
在应用模块的 `build.gradle` 或 `build.gradle.kts` 中添加 TIMPush 基础依赖。基础包提供 TIMPush 注册、监听和通用能力。
|
|
152
|
-
|
|
153
|
-
下方示例中的 `VERSION` 均指 TIMPush SDK 的版本号(如 `8.9.7537`),不是 Android 系统版本或厂商 SDK 版本。获取最新版本号请查看更新日志。
|
|
154
|
-
|
|
155
|
-
【Groovy DSL】
|
|
156
|
-
``` groovy
|
|
157
23
|
dependencies {
|
|
158
|
-
implementation 'com.tencent.timpush:timpush:
|
|
159
|
-
implementation 'com.tencent.liteav.tuikit:tuicore:VERSION'
|
|
24
|
+
implementation 'com.tencent.timpush:timpush:latest'
|
|
160
25
|
}
|
|
161
26
|
```
|
|
162
27
|
|
|
163
|
-
|
|
164
|
-
``` kotlin
|
|
165
|
-
dependencies {
|
|
166
|
-
implementation("com.tencent.timpush:timpush:VERSION")
|
|
167
|
-
implementation("com.tencent.liteav.tuikit:tuicore:VERSION")
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
添加依赖后,请在 Android Studio 中单击 **Sync Now**,或选择 **File > Sync Project with Gradle Files** 触发 Gradle 同步。
|
|
172
|
-
|
|
173
|
-
> **注意:**
|
|
174
|
-
> `TIMPush`、`TUICore` 和各厂商通道包建议使用相同 `VERSION`,避免依赖冲突。项目已接入 IM SDK 或 TUIKit 时,也需要确认相关 SDK 版本兼容。
|
|
175
|
-
>
|
|
176
|
-
|
|
177
|
-
**验证**:Gradle Sync 成功完成,无报错。如果报依赖找不到,请检查 `VERSION` 是否正确、腾讯云 Maven 仓库是否缺失。
|
|
178
|
-
|
|
179
|
-
#### 设置混淆规则
|
|
180
|
-
|
|
181
|
-
如果应用开启了代码混淆,请在 `proguard-rules.pro` 中加入 TIMPush 相关类不混淆规则。该配置用于避免 Release 包中 TIMPush 相关类、回调或厂商适配逻辑被混淆后无法正常调用:
|
|
182
|
-
``` proguard
|
|
183
|
-
-keep class com.tencent.qcloud.** { *; }
|
|
184
|
-
-keep class com.tencent.timpush.** { *; }
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
完成后,请重新构建 Release 包,并在真机上验证注册和收消息链路。
|
|
188
|
-
|
|
189
|
-
**验证**:App 可在目标厂商真机上正常安装和启动,无崩溃。如果启动崩溃,请检查 `Application` 声明、配置文件位置和 Manifest 合并错误。同时确认测试真机厂商与目标厂商通道一致(如不要在华为设备上验证荣耀通道)。
|
|
190
|
-
|
|
191
|
-
### 步骤2:集成厂商通道 SDK
|
|
192
|
-
|
|
193
|
-
请按目标厂商页签配置对应通道。只集成某个厂商时,只添加该厂商需要的配置文件、插件和依赖即可。
|
|
28
|
+
### 步骤3:集成厂商通道 SDK
|
|
194
29
|
|
|
195
30
|
【小米】
|
|
196
31
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
请先完成 小米厂商配置,并确认:
|
|
200
|
-
- 已在腾讯云控制台添加小米厂商证书;
|
|
201
|
-
|
|
202
|
-
- 已重新下载包含小米证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
203
|
-
|
|
204
|
-
- 使用小米真机验证。
|
|
205
|
-
|
|
206
|
-
#### **1. 集成 TIMPush 厂商依赖**
|
|
207
|
-
|
|
208
|
-
在应用模块 `build.gradle` 或 `build.gradle.kts` 的 `dependencies` 中追加小米通道包,`VERSION` 与基础包保持一致:
|
|
209
|
-
|
|
210
|
-
【Groovy DSL】
|
|
211
|
-
``` groovy
|
|
212
|
-
implementation 'com.tencent.timpush:xiaomi:VERSION'
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
【Kotlin DSL】
|
|
216
|
-
``` kotlin
|
|
217
|
-
implementation("com.tencent.timpush:xiaomi:VERSION")
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
集成结果判断:Gradle Sync 成功完成,无报错。
|
|
221
|
-
|
|
222
|
-
#### **2. 配置消息触达统计(可选)**
|
|
223
|
-
|
|
224
|
-
小米通道当前无需在客户端额外配置回执地址。如需统计,请按 小米厂商配置 完成控制台侧配置。
|
|
225
|
-
|
|
226
|
-
#### **3. 配置消息分类(可选)**
|
|
227
|
-
|
|
228
|
-
发送离线推送时可通过 SDK API 设置小米渠道 ID,API 设置优先级通常高于控制台证书默认配置。调用 [`setAndroidXiaoMiChannelID(String channelID)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#ac769aec48cdbc9a57416c5a79504617a) 设置小米渠道 `channelID`:
|
|
32
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加小米通道包:
|
|
229
33
|
``` java
|
|
230
|
-
|
|
231
|
-
pushInfo.setAndroidXiaoMiChannelID("your_xiaomi_channel_id");
|
|
34
|
+
implementation 'com.tencent.timpush:xiaomi:latest'
|
|
232
35
|
```
|
|
233
36
|
|
|
234
37
|
【华为】
|
|
235
38
|
|
|
236
|
-
#### **前置**
|
|
237
|
-
|
|
238
|
-
请先完成 华为厂商配置,并确认:
|
|
239
|
-
- 已在腾讯云控制台添加华为厂商证书;
|
|
240
|
-
|
|
241
|
-
- 已重新下载包含华为证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
242
|
-
|
|
243
|
-
- 测试包当前签名(debug 或 release)的 SHA-256 已在华为控制台「项目设置 > 常规 > SHA 证书指纹」中添加,指纹不一致会报 `6003: certificate fingerprint error`;
|
|
244
|
-
|
|
245
|
-
- 使用华为真机验证。
|
|
246
|
-
|
|
247
39
|
#### **1. 添加厂商配置文件**
|
|
248
40
|
|
|
249
|
-
``` text
|
|
250
|
-
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
修改项目、应用信息、证书指纹或服务配置后,建议重新下载并替换。后续构建时,华为 AGConnect 插件会读取该文件并将厂商要求的资源、Manifest 信息合并进应用包。
|
|
254
|
-
|
|
255
41
|
#### **2. 配置 Gradle 插件**
|
|
256
42
|
|
|
257
43
|
##### **追加厂商 Maven 仓库**
|
|
258
44
|
|
|
259
|
-
请在「配置 Gradle 仓库」已添加的公共仓库基础上,追加华为仓库。
|
|
260
|
-
|
|
261
45
|
【Gradle 7.1 及以上】
|
|
262
46
|
|
|
263
|
-
在 `settings.gradle`
|
|
264
|
-
|
|
265
|
-
【Groovy DSL】
|
|
47
|
+
在 `settings.gradle` 的 `pluginManagement > repositories` 和 `dependencyResolutionManagement > repositories` 中追加:
|
|
266
48
|
``` java
|
|
267
49
|
maven { url "https://developer.huawei.com/repo/" }
|
|
268
50
|
```
|
|
269
51
|
|
|
270
|
-
【Kotlin DSL】
|
|
271
|
-
``` java
|
|
272
|
-
maven { url = uri("https://developer.huawei.com/repo/") }
|
|
273
|
-
```
|
|
274
|
-
|
|
275
52
|
【Gradle 7.0 及以下】
|
|
276
53
|
|
|
277
54
|
在项目级 `build.gradle` 的 `buildscript > repositories`,以及 `settings.gradle` 的 `dependencyResolutionManagement > repositories`(Gradle 7.0)或 `allprojects > repositories`(Gradle 7.0 以下)中追加:
|
|
@@ -283,11 +60,7 @@ maven { url "https://developer.huawei.com/repo/" }
|
|
|
283
60
|
|
|
284
61
|
【Gradle 7.1 及以上】
|
|
285
62
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
如果项目级 `build.gradle.kts` 已通过 `plugins {}` 块声明 AGP,原有 `plugins {}` 块保留不动,在 `dependencies` 中声明 `com.android.tools.build:gradle` 即可。如果项目同时使用 Kotlin Android 插件,也请声明 `org.jetbrains.kotlin:kotlin-gradle-plugin`。
|
|
289
|
-
|
|
290
|
-
【Groovy DSL(build.gradle)】
|
|
63
|
+
在项目级 `build.gradle` 的 `buildscript > repositories` 中包含 `google()` 和华为仓库。
|
|
291
64
|
``` java
|
|
292
65
|
buildscript {
|
|
293
66
|
repositories {
|
|
@@ -307,32 +80,11 @@ buildscript {
|
|
|
307
80
|
}
|
|
308
81
|
}
|
|
309
82
|
```
|
|
310
|
-
|
|
311
|
-
【Kotlin DSL(build.gradle.kts)】
|
|
312
|
-
``` java
|
|
313
|
-
buildscript {
|
|
314
|
-
repositories {
|
|
315
|
-
google()
|
|
316
|
-
mavenCentral()
|
|
317
|
-
gradlePluginPortal()
|
|
318
|
-
maven { url = uri("https://mirrors.tencent.com/nexus/repository/maven-public/") }
|
|
319
|
-
maven { url = uri("https://developer.huawei.com/repo/") }
|
|
320
|
-
}
|
|
321
|
-
dependencies {
|
|
322
|
-
// 请与项目当前 Android Gradle Plugin 版本保持一致。
|
|
323
|
-
classpath("com.android.tools.build:gradle:<AGP_VERSION>")
|
|
324
|
-
// 如果项目使用 Kotlin Android 插件,请与项目当前 Kotlin Gradle Plugin 版本保持一致。
|
|
325
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:<KOTLIN_VERSION>")
|
|
326
|
-
// 华为 AGConnect。Gradle 8 / AGP 8 项目不要继续使用 1.6.0.300。
|
|
327
|
-
classpath("com.huawei.agconnect:agcp:1.9.1.301")
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
```
|
|
331
|
-
1. 请将`<AGP_VERSION>`替换为项目当前使用的 Android Gradle Plugin 版本,例如 `8.9.1`。如果项目级 `plugins {}` 块中已经声明了 `com.android.application` 版本,两个位置的 AGP 版本需要保持一致。
|
|
83
|
+
1. 请将`<AGP_VERSION>`替换为项目当前使用的 Android Gradle Plugin 版本,例如 `8.9.1`。
|
|
332
84
|
|
|
333
85
|
2. 请将`<KOTLIN_VERSION>` 替换为项目当前使用的 Kotlin Gradle Plugin 版本;如果项目未使用 Kotlin Android 插件,可删除该行。
|
|
334
86
|
|
|
335
|
-
>
|
|
87
|
+
> **警告:**
|
|
336
88
|
> 对于 Gradle 8 / AGP 8 项目,请不要继续使用 `com.huawei.agconnect:agcp:1.6.0.300`。AGP 8.0 已移除 Transform API,旧版 AGC 插件存在兼容风险,建议使用 `com.huawei.agconnect:agcp:1.9.1.301` 或更高已验证版本。
|
|
337
89
|
>
|
|
338
90
|
|
|
@@ -347,12 +99,8 @@ classpath 'com.huawei.agconnect:agcp:1.6.0.300'
|
|
|
347
99
|
|
|
348
100
|
##### **在应用模块启用插件**
|
|
349
101
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
如果应用模块中已经存在 `plugins` 块,请在现有 `plugins` 块中追加,不要重复添加已有的 `com.android.application` 插件。
|
|
353
|
-
|
|
354
|
-
【Groovy DSL(app/build.gradle)】
|
|
355
|
-
``` groovy
|
|
102
|
+
在应用模块的 `build.gradle` 中启用华为插件。
|
|
103
|
+
``` java
|
|
356
104
|
plugins {
|
|
357
105
|
// 华为 AGConnect。
|
|
358
106
|
id 'com.huawei.agconnect'
|
|
@@ -360,169 +108,37 @@ plugins {
|
|
|
360
108
|
// 或:apply plugin: 'com.huawei.agconnect'
|
|
361
109
|
```
|
|
362
110
|
|
|
363
|
-
【Kotlin DSL(app/build.gradle.kts)】
|
|
364
|
-
``` kotlin
|
|
365
|
-
plugins {
|
|
366
|
-
// 华为 AGConnect。
|
|
367
|
-
id("com.huawei.agconnect")
|
|
368
|
-
}
|
|
369
|
-
// 或:apply(plugin = "com.huawei.agconnect")
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
完成配置后,请在 Android Studio 中单击 **Sync Now**,或选择 **File > Sync Project with Gradle Files** 触发 Gradle 同步。同步成功后,再执行构建验证。
|
|
373
|
-
|
|
374
111
|
#### **3. 集成 TIMPush 厂商依赖**
|
|
375
112
|
|
|
376
|
-
在应用模块 `build.gradle`
|
|
377
|
-
|
|
378
|
-
【Groovy DSL】
|
|
379
|
-
``` groovy
|
|
380
|
-
implementation 'com.tencent.timpush:huawei:VERSION'
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
【Kotlin DSL】
|
|
384
|
-
``` kotlin
|
|
385
|
-
implementation("com.tencent.timpush:huawei:VERSION")
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
#### **4. 配置消息触达统计(可选)**
|
|
389
|
-
|
|
390
|
-
如需统计触达或点击数据,请配置回执地址 `https://api.im.qcloud.com/v3/offline_push_report/huawei`。华为推送证书 ID `<= 11344` 时使用华为推送 v2 接口,不支持触达和点击回执;如需支持统计,请重新生成并更新证书 ID。回执地址不配置或配置错误,都会影响触达统计。
|
|
391
|
-
|
|
392
|
-
#### **5. 配置消息分类(可选)**
|
|
393
|
-
|
|
394
|
-
发送离线推送时可通过 SDK API 设置华为消息分类,API 设置优先级通常高于控制台证书默认配置。调用 [`setAndroidHuaWeiCategory(String category)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#ad9dea3cb382c0c1a3c1a63738697fc1f) 设置华为推送消息分类:
|
|
113
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加华为通道包:
|
|
395
114
|
``` java
|
|
396
|
-
|
|
397
|
-
pushInfo.setAndroidHuaWeiCategory("IM");
|
|
115
|
+
implementation 'com.tencent.timpush:huawei:latest'
|
|
398
116
|
```
|
|
399
117
|
|
|
400
118
|
【OPPO】
|
|
401
119
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
请先完成 OPPO 厂商配置,并确认:
|
|
405
|
-
- 已在腾讯云控制台添加 OPPO 厂商证书;
|
|
406
|
-
|
|
407
|
-
- 已重新下载包含 OPPO 证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
408
|
-
|
|
409
|
-
- 使用 OPPO 真机验证。
|
|
410
|
-
|
|
411
|
-
#### **1. 集成 TIMPush 厂商依赖**
|
|
412
|
-
|
|
413
|
-
在应用模块 `build.gradle` 或 `build.gradle.kts` 的 `dependencies` 中追加 OPPO 通道包,`VERSION` 与基础包保持一致:
|
|
414
|
-
|
|
415
|
-
【Groovy DSL】
|
|
416
|
-
``` groovy
|
|
417
|
-
implementation 'com.tencent.timpush:oppo:VERSION'
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
【Kotlin DSL】
|
|
421
|
-
``` kotlin
|
|
422
|
-
implementation("com.tencent.timpush:oppo:VERSION")
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
集成结果判断:Gradle Sync 成功完成,无报错。
|
|
426
|
-
|
|
427
|
-
#### **2. 配置消息触达统计(可选)**
|
|
428
|
-
|
|
429
|
-
OPPO 通道当前无需在客户端额外配置回执地址。如需统计,请按 OPPO 厂商配置 完成控制台侧配置。
|
|
430
|
-
|
|
431
|
-
#### **3. 配置消息分类(可选)**
|
|
432
|
-
|
|
433
|
-
OPPO 同时存在新规则和旧规则,不要混用。
|
|
434
|
-
- 新规则:适用于新接入应用,或按 OPPO 新消息分类改造的应用。使用 `category`、私信模板参数,以及可选的 `notify_level`。
|
|
435
|
-
|
|
436
|
-
- 旧规则:仅适用于此前已开通 OPPO 私信通道权限的存量应用,使用已创建并在 OPPO 推送运营后台登记的私信通道 `ChannelID`。
|
|
437
|
-
|
|
438
|
-
只有 IM 聊天、订单、交易、账号变更等用户预期强、需要及时触达的消息,才建议申请或使用高优先级分类。营销、广告、活动、资讯类消息不应滥用高优分类,否则可能被厂商降级、限频或冻结权限。
|
|
439
|
-
|
|
440
|
-
发送离线推送时可通过 SDK API 设置,API 设置优先级通常高于控制台证书默认配置。
|
|
441
|
-
|
|
442
|
-
##### **OPPO 新规则配置**
|
|
443
|
-
|
|
444
|
-
OPPO 新接入应用建议使用新消息分类规则。IM 聊天、音视频通话等需要及时触达的消息,通常使用 `category=IM`,并按 OPPO 要求申请通讯与服务不限量权益或私信模板。
|
|
120
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加 OPPO 通道包:
|
|
445
121
|
``` java
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
// New OPPO message classification rule. Use IM for chat and call messages.
|
|
449
|
-
pushInfo.setAndroidOPPOCategory("IM");
|
|
450
|
-
|
|
451
|
-
// Optional. 1 = notification bar, 2 = notification bar + lock screen + sound + vibration.
|
|
452
|
-
// Use 16 only after OPPO strong reminder capability is approved.
|
|
453
|
-
pushInfo.setAndroidOPPONotifyLevel(2);
|
|
122
|
+
implementation 'com.tencent.timpush:oppo:latest'
|
|
454
123
|
```
|
|
455
124
|
|
|
456
|
-
对应 API:
|
|
457
|
-
- [`setAndroidOPPOCategory(String category)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a6a62542254c53626b81ce24380b0a2fb):设置 OPPO 新消息分类,例如 IM 消息使用 `IM`。
|
|
458
|
-
|
|
459
|
-
- [`setAndroidOPPONotifyLevel(int level)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a1fd2e7d168b5412fc263274842855c57):设置 OPPO 通知栏消息提醒等级。使用前需要先设置 `category`;如需 `16`,需先向 OPPO 申请强提醒能力。
|
|
460
|
-
|
|
461
|
-
如需使用 OPPO 私信模板,可通过 [`V2TIMOfflinePushInfo.setVendorParams(String vendorParams)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#aedaa6ba7f49f3abfc04a8efaaf45e0c7) 携带厂商扩展参数。根据腾讯云离线推送消息属性设置文档,`vendorParams` 是 JSON 字符串,且 `oppoTitleParam`、`oppoContentParam` 等字段本身也需要序列化为 JSON 字符串。
|
|
462
|
-
``` java
|
|
463
|
-
Map<String, Object> vendorParams = new HashMap<>();
|
|
464
|
-
vendorParams.put("oppoTemplateId", "OPPO 私信模板 ID");
|
|
465
|
-
|
|
466
|
-
Map<String, Object> titleParams = new HashMap<>();
|
|
467
|
-
titleParams.put("title", "推送标题");
|
|
468
|
-
vendorParams.put("oppoTitleParam", new Gson().toJson(titleParams));
|
|
469
|
-
|
|
470
|
-
Map<String, Object> contentParams = new HashMap<>();
|
|
471
|
-
contentParams.put("desc", "推送内容");
|
|
472
|
-
vendorParams.put("oppoContentParam", new Gson().toJson(contentParams));
|
|
473
|
-
|
|
474
|
-
pushInfo.setVendorParams(new Gson().toJson(vendorParams));
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
`vendorParams` 扩展参数能力要求 IMSDK 8.7 及以上版本。`oppoTemplateId` 必须是 OPPO 私信申请得到的模板 ID,不支持开发者自拟。`oppoTitleParam` 和 `oppoContentParam` 中的 key 需要与 OPPO 模板中的占位符一致。
|
|
478
|
-
|
|
479
|
-
##### **OPPO 旧规则配置**
|
|
480
|
-
|
|
481
|
-
旧规则仅适用于此前已开通 OPPO 私信通道权限的存量应用。如果应用仍按旧规则使用私信通道,请确保客户端创建的通道 ID 已在 OPPO 推送运营后台登记,并与发送离线推送时设置的 `channelID` 保持一致。
|
|
482
|
-
``` java
|
|
483
|
-
V2TIMOfflinePushInfo pushInfo = new V2TIMOfflinePushInfo();
|
|
484
|
-
|
|
485
|
-
// Old OPPO private channel rule for existing apps only.
|
|
486
|
-
pushInfo.setAndroidOPPOChannelID("your_oppo_private_channel_id");
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
新接入应用不要把 [`setAndroidOPPOChannelID`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a32d340e95395bb64cc3e8f62321aafe1) 当作 OPPO 新消息分类的必配项。新规则优先使用 [`setAndroidOPPOCategory`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a6a62542254c53626b81ce24380b0a2fb),并按需配置 [`setVendorParams`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#aedaa6ba7f49f3abfc04a8efaaf45e0c7) 和 [`setAndroidOPPONotifyLevel`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a1fd2e7d168b5412fc263274842855c57)。
|
|
490
|
-
|
|
491
125
|
【vivo】
|
|
492
126
|
|
|
493
|
-
#### **前置**
|
|
494
|
-
|
|
495
|
-
请先完成 vivo 厂商配置,并确认:
|
|
496
|
-
- 已在腾讯云控制台添加 vivo 厂商证书;
|
|
497
|
-
|
|
498
|
-
- 已重新下载包含 vivo 证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
499
|
-
|
|
500
|
-
- 使用 vivo 真机验证。
|
|
501
|
-
|
|
502
127
|
#### **1. 集成 TIMPush 厂商依赖**
|
|
503
128
|
|
|
504
|
-
在应用模块 `build.gradle`
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
``` groovy
|
|
508
|
-
implementation 'com.tencent.timpush:vivo:VERSION'
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
【Kotlin DSL】
|
|
512
|
-
``` kotlin
|
|
513
|
-
implementation("com.tencent.timpush:vivo:VERSION")
|
|
129
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加 vivo 通道包:
|
|
130
|
+
``` java
|
|
131
|
+
implementation 'com.tencent.timpush:vivo:latest'
|
|
514
132
|
```
|
|
515
133
|
|
|
516
134
|
#### **2. 配置 manifestPlaceholders 和 AndroidManifest.xml**
|
|
517
135
|
|
|
518
|
-
|
|
136
|
+
在 `manifestPlaceholders` 或直接在 `AndroidManifest.xml` 中配置 `meta-data`。
|
|
519
137
|
|
|
520
138
|
【方法 1:配置 manifestPlaceholders】
|
|
521
139
|
|
|
522
140
|
在 `manifestPlaceholders` 里添加条目:
|
|
523
|
-
|
|
524
|
-
【Groovy DSL】
|
|
525
|
-
``` groovy
|
|
141
|
+
``` java
|
|
526
142
|
android {
|
|
527
143
|
defaultConfig {
|
|
528
144
|
manifestPlaceholders = [
|
|
@@ -533,16 +149,6 @@ android {
|
|
|
533
149
|
}
|
|
534
150
|
```
|
|
535
151
|
|
|
536
|
-
【Kotlin DSL】
|
|
537
|
-
``` kotlin
|
|
538
|
-
android {
|
|
539
|
-
defaultConfig {
|
|
540
|
-
manifestPlaceholders["VIVO_APPKEY"] = "您应用分配的证书 APPKEY"
|
|
541
|
-
manifestPlaceholders["VIVO_APPID"] = "您应用分配的证书 APPID"
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
```
|
|
545
|
-
|
|
546
152
|
【方法 2:配置 AndroidManifest.xml】
|
|
547
153
|
|
|
548
154
|
在 `AndroidManifest.xml` 中配置 `meta-data`:
|
|
@@ -569,67 +175,26 @@ android {
|
|
|
569
175
|
</manifest>
|
|
570
176
|
```
|
|
571
177
|
|
|
572
|
-
集成结果判断:Gradle Sync 成功完成,无报错。
|
|
573
|
-
|
|
574
|
-
#### **3. 配置消息触达统计(可选)**
|
|
575
|
-
|
|
576
|
-
如需统计触达或点击数据,请配置回执地址 `https://api.im.qcloud.com/v3/offline_push_report/vivo`,并按控制台要求配置回执 ID。回执地址不配置或配置错误,都会影响触达统计。
|
|
577
|
-
|
|
578
|
-
#### **4. 配置消息分类(可选)**
|
|
579
|
-
|
|
580
|
-
发送离线推送时可通过 SDK API 设置 vivo 消息类别,API 设置优先级通常高于控制台证书默认配置。调用 [`setAndroidVIVOCategory(String category)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#ae7341caa3c58aec949cf186cb25af591) 设置 vivo 推送消息类别:
|
|
581
|
-
``` java
|
|
582
|
-
V2TIMOfflinePushInfo pushInfo = new V2TIMOfflinePushInfo();
|
|
583
|
-
pushInfo.setAndroidVIVOCategory("IM");
|
|
584
|
-
```
|
|
585
|
-
|
|
586
178
|
【荣耀】
|
|
587
179
|
|
|
588
|
-
#### **前置**
|
|
589
|
-
|
|
590
|
-
请先完成 荣耀厂商配置,并确认:
|
|
591
|
-
- 已在腾讯云控制台添加荣耀厂商证书;
|
|
592
|
-
|
|
593
|
-
- 已重新下载包含荣耀证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
594
|
-
|
|
595
|
-
- 测试包当前签名(debug 或 release)的 SHA-256 已在荣耀控制台「项目设置 > 常规 > SHA 证书指纹」中添加,指纹不一致会报 `6003: certificate fingerprint error`;
|
|
596
|
-
|
|
597
|
-
- 使用荣耀真机验证。不要在华为设备上验证荣耀通道。
|
|
598
|
-
|
|
599
180
|
#### **1. 添加厂商配置文件**
|
|
600
181
|
|
|
601
|
-
在荣耀开发者服务平台下载 `mcs-services.json
|
|
602
|
-
``` text
|
|
603
|
-
app/mcs-services.json
|
|
604
|
-
```
|
|
605
|
-
|
|
606
|
-
修改项目、应用信息或开发服务设置后,需要重新下载并替换。后续构建时,荣耀插件会读取该文件并将厂商要求的资源、Manifest 信息合并进应用包。
|
|
182
|
+
在荣耀开发者服务平台下载 `mcs-services.json`,添加到应用模块根目录:app/mcs-services.json。
|
|
607
183
|
|
|
608
184
|
#### **2. 配置 Gradle 插件**
|
|
609
185
|
|
|
610
|
-
荣耀需要通过 `com.hihonor.mcs:asplugin` 在构建期读取 `mcs-services.json`,并依赖荣耀 Maven 仓库解析插件与 SDK。荣耀官方示例统一使用 `buildscript > dependencies > classpath` 形式,未提供 `plugins {}` 块写法。
|
|
611
|
-
|
|
612
186
|
##### **追加厂商 Maven 仓库**
|
|
613
187
|
|
|
614
|
-
请在「配置 Gradle 仓库」已添加的公共仓库基础上,追加荣耀仓库。
|
|
615
|
-
|
|
616
188
|
【Gradle 7.1 及以上】
|
|
617
189
|
|
|
618
|
-
在 `settings.gradle`
|
|
619
|
-
|
|
620
|
-
【Groovy DSL】
|
|
190
|
+
在 `settings.gradle` 的 `pluginManagement > repositories` 和 `dependencyResolutionManagement > repositories` 中追加:
|
|
621
191
|
``` java
|
|
622
192
|
maven { url "https://developer.hihonor.com/repo" }
|
|
623
193
|
```
|
|
624
194
|
|
|
625
|
-
【Kotlin DSL】
|
|
626
|
-
``` java
|
|
627
|
-
maven { url = uri("https://developer.hihonor.com/repo") }
|
|
628
|
-
```
|
|
629
|
-
|
|
630
195
|
【Gradle 7.0 及以下】
|
|
631
196
|
|
|
632
|
-
在项目级 `build.gradle` 的 `buildscript > repositories
|
|
197
|
+
在项目级 `build.gradle` 的 `buildscript > repositories`,以及`allprojects > repositories`中追加:
|
|
633
198
|
``` groovy
|
|
634
199
|
maven { url "https://developer.hihonor.com/repo" }
|
|
635
200
|
```
|
|
@@ -638,9 +203,7 @@ maven { url "https://developer.hihonor.com/repo" }
|
|
|
638
203
|
|
|
639
204
|
【Gradle 7.1 及以上】
|
|
640
205
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
【Groovy DSL(build.gradle)】
|
|
206
|
+
请在项目级 Gradle 文件中额外补充 `buildscript` 配置,并在 `dependencies` 中声明 `com.android.tools.build:gradle`。
|
|
644
207
|
``` java
|
|
645
208
|
buildscript {
|
|
646
209
|
repositories {
|
|
@@ -656,32 +219,11 @@ buildscript {
|
|
|
656
219
|
// 如果项目使用 Kotlin Android 插件,请与项目当前 Kotlin Gradle Plugin 版本保持一致。
|
|
657
220
|
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:<KOTLIN_VERSION>'
|
|
658
221
|
// 荣耀 Push。
|
|
659
|
-
classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
```
|
|
663
|
-
|
|
664
|
-
【Kotlin DSL(build.gradle.kts)】
|
|
665
|
-
``` java
|
|
666
|
-
buildscript {
|
|
667
|
-
repositories {
|
|
668
|
-
google()
|
|
669
|
-
mavenCentral()
|
|
670
|
-
gradlePluginPortal()
|
|
671
|
-
maven { url = uri("https://mirrors.tencent.com/nexus/repository/maven-public/") }
|
|
672
|
-
maven { url = uri("https://developer.hihonor.com/repo") }
|
|
673
|
-
}
|
|
674
|
-
dependencies {
|
|
675
|
-
// 请与项目当前 Android Gradle Plugin 版本保持一致。
|
|
676
|
-
classpath("com.android.tools.build:gradle:<AGP_VERSION>")
|
|
677
|
-
// 如果项目使用 Kotlin Android 插件,请与项目当前 Kotlin Gradle Plugin 版本保持一致。
|
|
678
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:<KOTLIN_VERSION>")
|
|
679
|
-
// 荣耀 Push。
|
|
680
|
-
classpath("com.hihonor.mcs:asplugin:2.0.1.300")
|
|
222
|
+
classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
|
|
681
223
|
}
|
|
682
224
|
}
|
|
683
225
|
```
|
|
684
|
-
1. 请将`<AGP_VERSION>`替换为项目当前使用的 Android Gradle Plugin
|
|
226
|
+
1. 请将`<AGP_VERSION>`替换为项目当前使用的 Android Gradle Plugin 版本。
|
|
685
227
|
|
|
686
228
|
2. 请将`<KOTLIN_VERSION>` 替换为项目当前使用的 Kotlin Gradle Plugin 版本;如果项目未使用 Kotlin Android 插件,可删除该行。
|
|
687
229
|
|
|
@@ -694,12 +236,8 @@ classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
|
|
|
694
236
|
|
|
695
237
|
##### **在应用模块启用插件**
|
|
696
238
|
|
|
697
|
-
完成项目级插件依赖配置后,还需要在应用模块的 `build.gradle`
|
|
698
|
-
|
|
699
|
-
如果应用模块中已经存在 `plugins` 块,请在现有 `plugins` 块中追加,不要重复添加已有的 `com.android.application` 插件。应用级 `plugins { id("com.hihonor.mcs.asplugin") }` 可省略版本号(由项目级 classpath 提供),或改写为 `apply plugin`。
|
|
700
|
-
|
|
701
|
-
【Groovy DSL(app/build.gradle)】
|
|
702
|
-
``` groovy
|
|
239
|
+
完成项目级插件依赖配置后,还需要在应用模块的 `build.gradle` 中启用荣耀插件。
|
|
240
|
+
``` java
|
|
703
241
|
plugins {
|
|
704
242
|
// 荣耀 Push。
|
|
705
243
|
id 'com.hihonor.mcs.asplugin'
|
|
@@ -707,39 +245,19 @@ plugins {
|
|
|
707
245
|
// 或:apply plugin: 'com.hihonor.mcs.asplugin'
|
|
708
246
|
```
|
|
709
247
|
|
|
710
|
-
【Kotlin DSL(app/build.gradle.kts)】
|
|
711
|
-
``` kotlin
|
|
712
|
-
plugins {
|
|
713
|
-
// 荣耀 Push。
|
|
714
|
-
id("com.hihonor.mcs.asplugin")
|
|
715
|
-
}
|
|
716
|
-
// 或:apply(plugin = "com.hihonor.mcs.asplugin")
|
|
717
|
-
```
|
|
718
|
-
|
|
719
|
-
完成配置后,请在 Android Studio 中单击 **Sync Now**,或选择 **File > Sync Project with Gradle Files** 触发 Gradle 同步。
|
|
720
|
-
|
|
721
248
|
#### **3. 集成 TIMPush 厂商依赖**
|
|
722
249
|
|
|
723
|
-
在应用模块 `build.gradle`
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
``` groovy
|
|
727
|
-
implementation 'com.tencent.timpush:honor:VERSION'
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
【Kotlin DSL】
|
|
731
|
-
``` kotlin
|
|
732
|
-
implementation("com.tencent.timpush:honor:VERSION")
|
|
250
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加荣耀通道包:
|
|
251
|
+
``` java
|
|
252
|
+
implementation 'com.tencent.timpush:honor:latest'
|
|
733
253
|
```
|
|
734
254
|
|
|
735
255
|
#### **4. 配置 manifestPlaceholders 和 AndroidManifest.xml**
|
|
736
256
|
|
|
737
|
-
|
|
257
|
+
在 `manifestPlaceholders` 或 `AndroidManifest.xml` 中配置 `meta-data`。
|
|
738
258
|
|
|
739
259
|
【方法 1:配置 manifestPlaceholders】
|
|
740
|
-
|
|
741
|
-
【Groovy DSL】
|
|
742
|
-
``` groovy
|
|
260
|
+
``` java
|
|
743
261
|
android {
|
|
744
262
|
defaultConfig {
|
|
745
263
|
manifestPlaceholders = [
|
|
@@ -749,15 +267,6 @@ android {
|
|
|
749
267
|
}
|
|
750
268
|
```
|
|
751
269
|
|
|
752
|
-
【Kotlin DSL】
|
|
753
|
-
``` kotlin
|
|
754
|
-
android {
|
|
755
|
-
defaultConfig {
|
|
756
|
-
manifestPlaceholders["HONOR_APPID"] = "您应用分配的证书 APPID"
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
```
|
|
760
|
-
|
|
761
270
|
【方法 2:配置 AndroidManifest.xml】
|
|
762
271
|
``` xml
|
|
763
272
|
<application>
|
|
@@ -774,95 +283,29 @@ android {
|
|
|
774
283
|
``` xml
|
|
775
284
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
776
285
|
xmlns:tools="http://schemas.android.com/tools">
|
|
777
|
-
</manifest
|
|
778
|
-
```
|
|
779
|
-
|
|
780
|
-
集成结果判断:Gradle Sync 成功完成,无报错;确认 `mcs-services.json` 已放在应用模块根目录。
|
|
781
|
-
|
|
782
|
-
#### **5. 配置消息触达统计(可选)**
|
|
783
|
-
|
|
784
|
-
如需统计触达或点击数据,请配置回执地址 `https://api.im.qcloud.com/v3/offline_push_report/honor`。回执地址不配置或配置错误,都会影响触达统计。
|
|
785
|
-
|
|
786
|
-
#### **6. 配置消息分类(可选)**
|
|
787
|
-
|
|
788
|
-
发送离线推送时可通过 SDK API 设置荣耀消息分类,API 设置优先级通常高于控制台证书默认配置。调用 [`setAndroidHonorImportance(String importance)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a3167229118ad659378b2066821935c79) 设置荣耀消息分类,`NORMAL` 表示服务通讯类消息,`LOW` 表示资讯营销类消息:
|
|
789
|
-
``` java
|
|
790
|
-
V2TIMOfflinePushInfo pushInfo = new V2TIMOfflinePushInfo();
|
|
791
|
-
pushInfo.setAndroidHonorImportance("NORMAL");
|
|
286
|
+
</manifest>已添加的公共仓库基础上
|
|
792
287
|
```
|
|
793
288
|
|
|
794
289
|
【魅族】
|
|
795
290
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
请先完成 魅族厂商配置,并确认:
|
|
799
|
-
- 已在腾讯云控制台添加魅族厂商证书;
|
|
800
|
-
|
|
801
|
-
- 已重新下载包含魅族证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
802
|
-
|
|
803
|
-
- 使用魅族真机验证。
|
|
804
|
-
|
|
805
|
-
#### **1. 集成 TIMPush 厂商依赖**
|
|
806
|
-
|
|
807
|
-
在应用模块 `build.gradle` 或 `build.gradle.kts` 的 `dependencies` 中追加魅族通道包,`VERSION` 与基础包保持一致:
|
|
808
|
-
|
|
809
|
-
【Groovy DSL】
|
|
810
|
-
``` groovy
|
|
811
|
-
implementation 'com.tencent.timpush:meizu:VERSION'
|
|
812
|
-
```
|
|
813
|
-
|
|
814
|
-
【Kotlin DSL】
|
|
815
|
-
``` kotlin
|
|
816
|
-
implementation("com.tencent.timpush:meizu:VERSION")
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
集成结果判断:Gradle Sync 成功完成,无报错。
|
|
820
|
-
|
|
821
|
-
#### **2. 配置消息触达统计(可选)**
|
|
822
|
-
|
|
823
|
-
如需统计触达或点击数据,请打开回执开关并配置回执地址 `https://api.im.qcloud.com/v3/offline_push_report/meizu`。回执地址不配置或配置错误,都会影响触达统计。
|
|
824
|
-
|
|
825
|
-
#### **3. 配置消息分类(可选)**
|
|
826
|
-
|
|
827
|
-
发送离线推送时可通过 SDK API 设置魅族消息分类,API 设置优先级通常高于控制台证书默认配置。调用 [`setAndroidMeizuNotifyType(int type)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a7e26dd03042cad06c4e7352845079be0) 设置魅族消息分类,`0` 表示公信消息,`1` 表示私信消息:
|
|
291
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加魅族通道包:
|
|
828
292
|
``` java
|
|
829
|
-
|
|
830
|
-
pushInfo.setAndroidMeizuNotifyType(1);
|
|
293
|
+
implementation 'com.tencent.timpush:meizu:latest'
|
|
831
294
|
```
|
|
832
295
|
|
|
833
296
|
【Google FCM】
|
|
834
297
|
|
|
835
|
-
#### **前置**
|
|
836
|
-
|
|
837
|
-
请先完成 Google FCM 厂商配置,并确认:
|
|
838
|
-
- 已在腾讯云控制台添加 FCM 厂商证书;
|
|
839
|
-
|
|
840
|
-
- 已重新下载包含 FCM 证书的 `timpush-configs.json`,并放入应用模块 `assets` 目录;
|
|
841
|
-
|
|
842
|
-
- 测试设备具备可用的 Google Play 服务(国内无 GMS 的设备无法验证 FCM 通道)。
|
|
843
|
-
|
|
844
298
|
#### **1. 添加厂商配置文件**
|
|
845
299
|
|
|
846
|
-
在 Firebase 控制台下载 `google-services.json
|
|
847
|
-
``` text
|
|
848
|
-
app/google-services.json
|
|
849
|
-
```
|
|
850
|
-
|
|
851
|
-
后续构建时,Google Services 插件会读取该文件并将 FCM 要求的资源、Manifest 信息合并进应用包。
|
|
300
|
+
在 Firebase 控制台下载 `google-services.json`,添加到应用模块根目录:app/google-services.json。
|
|
852
301
|
|
|
853
302
|
#### **2. 配置 Gradle 插件**
|
|
854
303
|
|
|
855
|
-
Google FCM 需要通过 Google Services Gradle 插件在构建期读取 `google-services.json`。请按工程 Gradle 版本选择配置方式。FCM 无需额外的厂商 Maven 仓库,相关依赖通过 `google()` 仓库解析。
|
|
856
|
-
|
|
857
304
|
##### **配置项目级插件依赖**
|
|
858
305
|
|
|
859
306
|
【Gradle 7.1 及以上】
|
|
860
307
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
如果项目级 `build.gradle.kts` 已通过 `plugins {}` 块声明 AGP(新建 Kotlin DSL 项目的默认方式),原有 `plugins {}` 块保留不动,不需要整体迁移到 `buildscript` 写法,在 `dependencies` 中声明 `com.android.tools.build:gradle` 即可。如果项目同时使用 Kotlin Android 插件,也请声明 `org.jetbrains.kotlin:kotlin-gradle-plugin`。
|
|
864
|
-
|
|
865
|
-
【Groovy DSL(build.gradle)】
|
|
308
|
+
在项目级 `build.gradle` 的 `buildscript > repositories` 中包含 `google()` 等仓库:
|
|
866
309
|
``` java
|
|
867
310
|
buildscript {
|
|
868
311
|
repositories {
|
|
@@ -881,27 +324,7 @@ buildscript {
|
|
|
881
324
|
}
|
|
882
325
|
}
|
|
883
326
|
```
|
|
884
|
-
|
|
885
|
-
【Kotlin DSL(build.gradle.kts)】
|
|
886
|
-
``` java
|
|
887
|
-
buildscript {
|
|
888
|
-
repositories {
|
|
889
|
-
google()
|
|
890
|
-
mavenCentral()
|
|
891
|
-
gradlePluginPortal()
|
|
892
|
-
maven { url = uri("https://mirrors.tencent.com/nexus/repository/maven-public/") }
|
|
893
|
-
}
|
|
894
|
-
dependencies {
|
|
895
|
-
// 请与项目当前 Android Gradle Plugin 版本保持一致。
|
|
896
|
-
classpath("com.android.tools.build:gradle:<AGP_VERSION>")
|
|
897
|
-
// 如果项目使用 Kotlin Android 插件,请与项目当前 Kotlin Gradle Plugin 版本保持一致。
|
|
898
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:<KOTLIN_VERSION>")
|
|
899
|
-
// Google FCM。4.4.2 要求 AGP 7.3.0 及以上,更低的 AGP 请改用 4.3.15。
|
|
900
|
-
classpath("com.google.gms:google-services:4.4.2")
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
```
|
|
904
|
-
1. 请将`<AGP_VERSION>`替换为项目当前使用的 Android Gradle Plugin 版本,例如 `8.9.1`。如果项目级 `plugins {}` 块中已经声明了 `com.android.application` 版本,两个位置的 AGP 版本需要保持一致。
|
|
327
|
+
1. 请将`<AGP_VERSION>`替换为项目当前使用的 Android Gradle Plugin 版本。
|
|
905
328
|
|
|
906
329
|
2. 请将`<KOTLIN_VERSION>` 替换为项目当前使用的 Kotlin Gradle Plugin 版本;如果项目未使用 Kotlin Android 插件,可删除该行。
|
|
907
330
|
|
|
@@ -918,12 +341,8 @@ classpath 'com.google.gms:google-services:4.3.15'
|
|
|
918
341
|
|
|
919
342
|
##### **在应用模块启用插件**
|
|
920
343
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
如果应用模块中已经存在 `plugins` 块,请在现有 `plugins` 块中追加,不要重复添加已有的 `com.android.application` 插件。
|
|
924
|
-
|
|
925
|
-
【Groovy DSL(app/build.gradle)】
|
|
926
|
-
``` groovy
|
|
344
|
+
在应用模块的 `build.gradle` 中启用 Google Services 插件。
|
|
345
|
+
``` java
|
|
927
346
|
plugins {
|
|
928
347
|
// Google FCM。
|
|
929
348
|
id 'com.google.gms.google-services'
|
|
@@ -931,275 +350,103 @@ plugins {
|
|
|
931
350
|
// 或:apply plugin: 'com.google.gms.google-services'
|
|
932
351
|
```
|
|
933
352
|
|
|
934
|
-
【Kotlin DSL(app/build.gradle.kts)】
|
|
935
|
-
``` kotlin
|
|
936
|
-
plugins {
|
|
937
|
-
// Google FCM。
|
|
938
|
-
id("com.google.gms.google-services")
|
|
939
|
-
}
|
|
940
|
-
// 或:apply(plugin = "com.google.gms.google-services")
|
|
941
|
-
```
|
|
942
|
-
|
|
943
|
-
完成配置后,请在 Android Studio 中单击 **Sync Now**,或选择 **File > Sync Project with Gradle Files** 触发 Gradle 同步。同步成功后,再执行构建验证。
|
|
944
|
-
|
|
945
353
|
#### **3. 集成 TIMPush 厂商依赖**
|
|
946
354
|
|
|
947
|
-
在应用模块 `build.gradle`
|
|
948
|
-
|
|
949
|
-
【Groovy DSL】
|
|
950
|
-
``` groovy
|
|
951
|
-
implementation 'com.tencent.timpush:fcm:VERSION'
|
|
952
|
-
```
|
|
953
|
-
|
|
954
|
-
【Kotlin DSL】
|
|
955
|
-
``` kotlin
|
|
956
|
-
implementation("com.tencent.timpush:fcm:VERSION")
|
|
957
|
-
```
|
|
958
|
-
|
|
959
|
-
集成结果判断:Gradle Sync 成功完成,无报错;确认 `google-services.json` 已放在应用模块根目录。
|
|
960
|
-
|
|
961
|
-
#### **4. 配置消息触达统计(可选)**
|
|
962
|
-
|
|
963
|
-
FCM 暂不支持推送统计功能。
|
|
964
|
-
|
|
965
|
-
#### **5. 配置消息分类(可选)**
|
|
966
|
-
|
|
967
|
-
Android 8.0 及以上可通过通知渠道 ID 控制 FCM 通知展示策略。渠道创建与配置见 Google FCM 厂商配置。发送离线推送时可通过 SDK API 设置,API 设置优先级通常高于控制台证书默认配置。调用 [`setAndroidFCMChannelID(String channelID)`](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html#a1e63514ec664a5f7bc8c6a5b09f0689e) 设置 FCM 通道通知渠道 ID:
|
|
355
|
+
在应用模块 `build.gradle` 的 `dependencies` 中追加 FCM 通道包:
|
|
968
356
|
``` java
|
|
969
|
-
|
|
970
|
-
pushInfo.setAndroidFCMChannelID("your_fcm_channel_id");
|
|
357
|
+
implementation 'com.tencent.timpush:fcm:latest'
|
|
971
358
|
```
|
|
972
359
|
|
|
973
|
-
|
|
974
|
-
> 请关注各厂商通道消息分类规则:
|
|
975
|
-
>
|
|
976
|
-
> 1. 厂商离线通道的消息分类机制会影响推送及时性、单设备每日接收数量、夜间展示、声音、横幅和厂商通道权限。
|
|
977
|
-
> 2. 只有 IM 聊天、订单、交易、账号变更等用户预期强、需要及时触达的消息,才建议申请或使用高优先级分类。营销、广告、活动、资讯类消息不应滥用高优分类,**否则可能被厂商降级、限频或冻结权限。**
|
|
978
|
-
> 3. 发送离线推送时,API 设置优先级高于腾讯云控制台证书默认配置。
|
|
360
|
+
厂商消息分类机制会影响消息推送的及时性,参考文档 厂商消息分类限制和使用指南 处理。
|
|
979
361
|
|
|
980
|
-
### 步骤
|
|
362
|
+
### 步骤4:注册推送服务
|
|
981
363
|
|
|
982
364
|
#### 调用 registerPush
|
|
983
365
|
|
|
984
|
-
registerPush
|
|
985
|
-
|
|
986
|
-
`appKey` 的取值会影响注册方式和可用的推送标识:
|
|
987
|
-
- `appKey = Push Key`:注册 TIMPush 独立推送能力。Push Key 客户端密钥。
|
|
988
|
-
|
|
989
|
-
- `appKey = null`:复用 IM 登录态注册推送,必须在 IM `login` 成功后调用。
|
|
990
|
-
|
|
991
|
-
请先根据业务场景确认调用顺序:
|
|
992
|
-
|
|
993
|
-
| <strong>场景</strong> | <strong>调用顺序</strong> | <strong>服务端可用于发送推送的目标标识</strong> | <strong>说明</strong> |
|
|
994
|
-
| --- | --- | --- | --- |
|
|
995
|
-
| 仅使用 TIMPush | App 每次冷启动后调用<br><code>registerPush(appKey = Push Key)</code> | <code>registrationID</code> | 适用于营销 / 活动 / 通知推送,不接入 IM SDK。 |
|
|
996
|
-
| IM SDK + TIMPush<br>先注册 Push 再登录 | <code>registerPush(appKey = Push Key)</code><br>→ IM <code>login</code> | 登录前:<code>registrationID</code>;<br>登录后:<code>registrationID</code> + <code>userID</code> | 适用于希望用户未登录时也能收到营销推送的场景。 |
|
|
997
|
-
| IM SDK + TIMPush<br>先登录再注册 Push | IM <code>login</code><br>→ <code>registerPush(appKey = null)</code> | 登录后:<code>userID</code><br>注册后:<code>userID</code> + <code>registrationID</code>,<br>此时 <code>registrationID</code> = <code>userID</code> | 适用于希望用户登录后能收到 Chat 离线消息和营销推送的场景。 |
|
|
998
|
-
|
|
999
|
-
> **注意:**
|
|
1000
|
-
>
|
|
1001
|
-
> - 如果用户退出 IM SDK,同时集成了 IM SDK + TIMPush 的场景下已建立的 `userID` 与 `registrationID` 推送关系都会失效,需要重新完成对应注册。
|
|
1002
|
-
> - Chat 应用的密钥仅用于 IM 登录,不能作为 `registerPush` 的 `appKey`。
|
|
1003
|
-
|
|
1004
|
-
【App 冷启动注册 TIMPush(appKey 传 Push Key)】
|
|
1005
|
-
|
|
1006
|
-
App 冷启动、用户同意隐私政策后调用 `registerPush(appKey = Push Key)`。如果工程已有自定义 `Application`,将注册逻辑放在该类中;如果没有,需新建并在 `AndroidManifest.xml` 中声明。
|
|
366
|
+
registerPush 用于向腾讯云 Push 后台注册当前设备的推送 token。请在用户同意隐私政策后调用 `registerPush(appKey = Push Key)`,示例代码如下所示:
|
|
1007
367
|
|
|
1008
368
|
【Java】
|
|
1009
369
|
``` java
|
|
1010
|
-
import android.app.Application;
|
|
1011
370
|
import android.util.Log;
|
|
1012
371
|
import com.tencent.timpush.TIMPushCallback;
|
|
1013
372
|
import com.tencent.timpush.TIMPushManager;
|
|
1014
373
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
@Override
|
|
1019
|
-
public void onCreate() {
|
|
1020
|
-
super.onCreate();
|
|
1021
|
-
registerTIMPush();
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
private void registerTIMPush() {
|
|
1025
|
-
int sdkAppId = 0; // TODO: Replace with your SDKAppID.
|
|
1026
|
-
String appKey = "您的客户端密钥"; // TODO: Replace with your Push Key.
|
|
1027
|
-
|
|
1028
|
-
TIMPushManager.getInstance().registerPush(this, sdkAppId, appKey, new TIMPushCallback<Object>() {
|
|
1029
|
-
@Override
|
|
1030
|
-
public void onSuccess(Object data) {
|
|
1031
|
-
Log.d(TAG, ">>>>> registerPush success, data = " + data);
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
@Override
|
|
1035
|
-
public void onError(int errCode, String errMsg, Object data) {
|
|
1036
|
-
Log.e(TAG, ">>>>> registerPush failed, errCode = " + errCode
|
|
1037
|
-
+ ", errMsg = " + errMsg);
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
```
|
|
1043
|
-
|
|
1044
|
-
【Kotlin】
|
|
1045
|
-
``` java
|
|
1046
|
-
import android.app.Application
|
|
1047
|
-
import android.util.Log
|
|
1048
|
-
import com.tencent.timpush.TIMPushCallback
|
|
1049
|
-
import com.tencent.timpush.TIMPushManager
|
|
1050
|
-
|
|
1051
|
-
class App : Application() {
|
|
1052
|
-
override fun onCreate() {
|
|
1053
|
-
super.onCreate()
|
|
1054
|
-
registerTIMPush()
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
private fun registerTIMPush() {
|
|
1058
|
-
val sdkAppId = 0 // TODO: Replace with your SDKAppID.
|
|
1059
|
-
val appKey = "您的客户端密钥" // TODO: Replace with your Push Key.
|
|
1060
|
-
|
|
1061
|
-
TIMPushManager.getInstance().registerPush(this, sdkAppId, appKey, object : TIMPushCallback<Any?>() {
|
|
1062
|
-
override fun onSuccess(data: Any?) {
|
|
1063
|
-
Log.d("TIMPush", ">>>>> registerPush success, data = $data")
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
override fun onError(errCode: Int, errMsg: String?, data: Any?) {
|
|
1067
|
-
Log.e("TIMPush", ">>>>> registerPush failed, errCode = $errCode, errMsg = $errMsg")
|
|
1068
|
-
}
|
|
1069
|
-
})
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
```
|
|
1073
|
-
|
|
1074
|
-
在 `AndroidManifest.xml` 中声明 `Application`:
|
|
1075
|
-
``` xml
|
|
1076
|
-
<application
|
|
1077
|
-
android:name=".App"
|
|
1078
|
-
...>
|
|
1079
|
-
</application>
|
|
1080
|
-
```
|
|
1081
|
-
|
|
1082
|
-
【IM 登录后注册推送(appKey 传 null)】
|
|
1083
|
-
|
|
1084
|
-
请在 IM `login` 成功回调中调用 `registerPush(appKey = null)`。
|
|
1085
|
-
|
|
1086
|
-
【Java】
|
|
1087
|
-
``` java
|
|
1088
|
-
import android.content.Context;
|
|
1089
|
-
import android.util.Log;
|
|
1090
|
-
|
|
1091
|
-
import com.tencent.imsdk.v2.V2TIMCallback;
|
|
1092
|
-
import com.tencent.imsdk.v2.V2TIMManager;
|
|
1093
|
-
import com.tencent.imsdk.v2.V2TIMSDKConfig;
|
|
1094
|
-
import com.tencent.qcloud.tim.push.TIMPushCallback;
|
|
1095
|
-
import com.tencent.qcloud.tim.push.TIMPushManager;
|
|
1096
|
-
|
|
1097
|
-
public void loginIMAndRegisterPush(Context context) {
|
|
374
|
+
// 在用户同意隐私政策后调用
|
|
375
|
+
private void registerTIMPush() {
|
|
1098
376
|
int sdkAppId = 0; // TODO: Replace with your SDKAppID.
|
|
1099
|
-
String
|
|
1100
|
-
String userSig = "<YOUR_USER_SIG>";
|
|
1101
|
-
|
|
1102
|
-
boolean initSuccess = V2TIMManager.getInstance().initSDK(context, sdkAppId, new V2TIMSDKConfig());
|
|
1103
|
-
if (!initSuccess) {
|
|
1104
|
-
Log.e("TIMPush", ">>>>> IM SDK init failed");
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
377
|
+
String appKey = "您的客户端密钥"; // TODO: Replace with your Push Key.
|
|
1107
378
|
|
|
1108
|
-
|
|
379
|
+
TIMPushManager.getInstance().registerPush(this, sdkAppId, appKey, new TIMPushCallback<Object>() {
|
|
1109
380
|
@Override
|
|
1110
|
-
public void onSuccess() {
|
|
1111
|
-
|
|
381
|
+
public void onSuccess(Object data) {
|
|
382
|
+
Log.d("TIMPush", ">>>>> registerPush success, data = " + data);
|
|
383
|
+
// 获取并打印出 registrationID,方便后续根据 registrationID 发送离线推送消息
|
|
384
|
+
TIMPushManager.getInstance().getRegistrationID(new TIMPushCallback<Object>() {
|
|
1112
385
|
@Override
|
|
1113
386
|
public void onSuccess(Object data) {
|
|
1114
|
-
|
|
387
|
+
String registrationID = (String) data;
|
|
388
|
+
Log.d("TIMPush", ">>>>> getRegistrationID success, registrationID = " + registrationID);
|
|
1115
389
|
}
|
|
1116
|
-
|
|
1117
390
|
@Override
|
|
1118
391
|
public void onError(int errCode, String errMsg, Object data) {
|
|
1119
|
-
Log.e("TIMPush", ">>>>>
|
|
392
|
+
Log.e("TIMPush", ">>>>> getRegistrationID failed, errCode = " + errCode
|
|
1120
393
|
+ ", errMsg = " + errMsg);
|
|
1121
394
|
}
|
|
1122
395
|
});
|
|
1123
396
|
}
|
|
1124
397
|
|
|
1125
398
|
@Override
|
|
1126
|
-
public void onError(int
|
|
1127
|
-
Log.e("TIMPush", ">>>>>
|
|
399
|
+
public void onError(int errCode, String errMsg, Object data) {
|
|
400
|
+
Log.e("TIMPush", ">>>>> registerPush failed, errCode = " + errCode
|
|
401
|
+
+ ", errMsg = " + errMsg);
|
|
1128
402
|
}
|
|
1129
403
|
});
|
|
1130
404
|
}
|
|
405
|
+
|
|
1131
406
|
```
|
|
1132
407
|
|
|
1133
408
|
【Kotlin】
|
|
1134
409
|
``` java
|
|
1135
|
-
import android.content.Context
|
|
1136
410
|
import android.util.Log
|
|
1137
|
-
import com.tencent.
|
|
1138
|
-
import com.tencent.
|
|
1139
|
-
import com.tencent.imsdk.v2.V2TIMSDKConfig
|
|
1140
|
-
import com.tencent.qcloud.tim.push.TIMPushCallback
|
|
1141
|
-
import com.tencent.qcloud.tim.push.TIMPushManager
|
|
411
|
+
import com.tencent.timpush.TIMPushCallback
|
|
412
|
+
import com.tencent.timpush.TIMPushManager
|
|
1142
413
|
|
|
1143
|
-
|
|
414
|
+
// 在用户同意隐私政策后调用
|
|
415
|
+
private fun registerTIMPush() {
|
|
1144
416
|
val sdkAppId = 0 // TODO: Replace with your SDKAppID.
|
|
1145
|
-
val
|
|
1146
|
-
val userSig = "<YOUR_USER_SIG>"
|
|
1147
|
-
|
|
1148
|
-
val initSuccess = V2TIMManager.getInstance().initSDK(context, sdkAppId, V2TIMSDKConfig())
|
|
1149
|
-
if (!initSuccess) {
|
|
1150
|
-
Log.e("TIMPush", ">>>>> IM SDK init failed")
|
|
1151
|
-
return
|
|
1152
|
-
}
|
|
417
|
+
val appKey = "您的客户端密钥" // TODO: Replace with your Push Key.
|
|
1153
418
|
|
|
1154
|
-
|
|
1155
|
-
override fun onSuccess() {
|
|
1156
|
-
|
|
419
|
+
TIMPushManager.getInstance().registerPush(this, sdkAppId, appKey, object : TIMPushCallback<Any?>() {
|
|
420
|
+
override fun onSuccess(data: Any?) {
|
|
421
|
+
Log.d("TIMPush", ">>>>> registerPush success, data = $data")
|
|
422
|
+
// 获取并打印出 registrationID,方便后续根据 registrationID 发送离线推送消息
|
|
423
|
+
TIMPushManager.getInstance().getRegistrationID(object : TIMPushCallback<Any?>() {
|
|
1157
424
|
override fun onSuccess(data: Any?) {
|
|
1158
|
-
Log.d("TIMPush", ">>>>>
|
|
425
|
+
Log.d("TIMPush", ">>>>> getRegistrationID success, registrationID = $data")
|
|
1159
426
|
}
|
|
1160
|
-
|
|
1161
427
|
override fun onError(errCode: Int, errMsg: String?, data: Any?) {
|
|
1162
|
-
Log.e("TIMPush", ">>>>>
|
|
428
|
+
Log.e("TIMPush", ">>>>> getRegistrationID failed, errCode = $errCode, errMsg = $errMsg")
|
|
1163
429
|
}
|
|
1164
430
|
})
|
|
1165
431
|
}
|
|
1166
432
|
|
|
1167
|
-
override fun onError(
|
|
1168
|
-
Log.e("TIMPush", ">>>>>
|
|
433
|
+
override fun onError(errCode: Int, errMsg: String?, data: Any?) {
|
|
434
|
+
Log.e("TIMPush", ">>>>> registerPush failed, errCode = $errCode, errMsg = $errMsg")
|
|
1169
435
|
}
|
|
1170
436
|
})
|
|
1171
437
|
}
|
|
1172
438
|
```
|
|
1173
439
|
|
|
1174
|
-
|
|
1175
|
-
>
|
|
1176
|
-
> 如果您的业务仅使用即时通信 IM 聊天能力,请勿在 IM 登录前先调用 `registerPush`。否则 SDK 可能会按独立推送场景注册 Push 类型账号,并产生对应的 Push DAU。Push DAU 超出套餐额度后,可能会产生额外费用。
|
|
1177
|
-
>
|
|
1178
|
-
|
|
1179
|
-
**验证**:
|
|
1180
|
-
|
|
1181
|
-
1. `registerPush` 的 `onSuccess` 回调被触发。
|
|
1182
|
-
|
|
1183
|
-
2. 登录腾讯云控制台 > 即时通信 IM > **推送服务 Push** > **推送排查**,按当前场景输入 `registrationID` 或 `userID`,确认 token 已上传。
|
|
1184
|
-
|
|
1185
|
-
3. 如触发 `onError`,可按 错误码 查询 `code` 含义。
|
|
1186
|
-
|
|
1187
|
-
#### 自定义 registrationID(可选)
|
|
1188
|
-
|
|
1189
|
-
如需自定义推送标识(如使用业务侧用户 ID),可在 `registerPush` 前调用 setRegistrationID。
|
|
440
|
+
如触发 `onError`,可按 错误码 查询 `code` 含义。
|
|
1190
441
|
|
|
1191
|
-
|
|
1192
|
-
> 混用场景下,自定义 `registrationID` 必须与 IM 登录使用的 `userID` 完全一致,否则会产生账号互踢导致推送丢失。
|
|
1193
|
-
>
|
|
1194
|
-
|
|
1195
|
-
### 步骤4:测试推送链路
|
|
442
|
+
### 步骤5:测试推送链路
|
|
1196
443
|
|
|
1197
|
-
|
|
444
|
+
完成上述集成步骤后,需要通过发送测试消息验证链路是否打通,请确认:
|
|
1198
445
|
1. Android 13 及以上已允许通知权限;
|
|
1199
446
|
|
|
1200
447
|
2. Android 8.0 及以上目标通知渠道已开启(包括横幅、锁屏、声音开关);
|
|
1201
448
|
|
|
1202
|
-
3.
|
|
449
|
+
3. App 已置于后台或杀进程。
|
|
1203
450
|
|
|
1204
451
|
发送测试消息可以采用下面几种方法:
|
|
1205
452
|
|
|
@@ -1207,7 +454,7 @@ fun loginIMAndRegisterPush(context: Context) {
|
|
|
1207
454
|
|
|
1208
455
|
仅集成 TIMPush 的用户,建议优先使用腾讯云控制台接入测试能力验证离线推送。
|
|
1209
456
|
|
|
1210
|
-
操作路径:腾讯云控制台 > **推送服务 Push** > **接入测试**。在接入测试页面,可以指定 `registrationID`
|
|
457
|
+
操作路径:腾讯云控制台 > **推送服务 Push** > **接入测试**。在接入测试页面,可以指定 `registrationID` 发送离线推送测试。
|
|
1211
458
|
|
|
1212
459
|
【REST API 发送】
|
|
1213
460
|
|
|
@@ -1222,17 +469,10 @@ pushInfo.setTitle("推送标题");
|
|
|
1222
469
|
pushInfo.setDesc("推送内容");
|
|
1223
470
|
pushInfo.setExt("业务自定义 ext".getBytes());
|
|
1224
471
|
|
|
1225
|
-
V2TIMManager.getMessageManager().sendMessage(
|
|
1226
|
-
v2TIMMessage,
|
|
1227
|
-
userID,
|
|
1228
|
-
null,
|
|
1229
|
-
V2TIMMessage.V2TIM_PRIORITY_DEFAULT,
|
|
1230
|
-
false,
|
|
1231
|
-
pushInfo,
|
|
472
|
+
V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, pushInfo,
|
|
1232
473
|
new V2TIMSendCallback<V2TIMMessage>() {
|
|
1233
474
|
@Override
|
|
1234
|
-
public void onProgress(int progress) {
|
|
1235
|
-
}
|
|
475
|
+
public void onProgress(int progress) {}
|
|
1236
476
|
|
|
1237
477
|
@Override
|
|
1238
478
|
public void onError(int code, String desc) {
|
|
@@ -1249,224 +489,7 @@ V2TIMManager.getMessageManager().sendMessage(
|
|
|
1249
489
|
|
|
1250
490
|
`sendMessage` 属于 IMSDK 消息发送能力。仅集成 TIMPush 的用户不需要为了验证离线推送而额外接入完整 Chat 初始化、登录和消息发送流程。
|
|
1251
491
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
通知点击跳转需要三步配合完成:控制台配置点击动作、发送推送时携带跳转参数、客户端注册监听并解析参数。三步缺一则跳转不生效。
|
|
1255
|
-
|
|
1256
|
-
#### **配置控制台点击动作**
|
|
1257
|
-
|
|
1258
|
-
在腾讯云控制台配置推送证书的「点击后续动作」,勾选「打开应用内指定页面」:
|
|
1259
|
-
|
|
1260
|
-
操作路径:腾讯云控制台 > **推送服务 Push** > **基础配置** > **对应厂商证书** > **编辑** > 点击后续动作,选择**打开应用内指定界面**。
|
|
1261
|
-
|
|
1262
|
-
#### **发送推送时携带** `ext`
|
|
1263
|
-
|
|
1264
|
-
发送离线推送时,通过 `ext` 字段携带跳转所需的业务信息(如目标页面、会话 ID 等)。`ext` 是一个字符串,结构由业务自定义,推荐使用 JSON 格式便于客户端解析。下文示例统一使用如下结构演示:
|
|
1265
|
-
``` json
|
|
1266
|
-
# conversationType 为 1 表示单聊(conversationID 填消息发送方 userID),为 2 表示群聊(conversationID 填 groupID)。
|
|
1267
|
-
{"conversationID":"user_A","conversationType":1}
|
|
1268
|
-
```
|
|
1269
|
-
|
|
1270
|
-
【REST API 发送】
|
|
1271
|
-
|
|
1272
|
-
通过 REST API 发送推送时,在请求体的 `Ext` 字段中设置 JSON 字符串:
|
|
1273
|
-
``` json
|
|
1274
|
-
{
|
|
1275
|
-
"MsgBody": [],
|
|
1276
|
-
"OfflinePushInfo": {
|
|
1277
|
-
"PushFlag": 0,
|
|
1278
|
-
"Title": "离线推送标题",
|
|
1279
|
-
"Desc": "离线推送内容",
|
|
1280
|
-
"Ext": "{\"conversationID\":\"user_A\",\"conversationType\":1}"
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
```
|
|
1284
|
-
|
|
1285
|
-
控制台接入测试页面同样支持设置 `Ext` 字段,填入 JSON 字符串即可。
|
|
1286
|
-
|
|
1287
|
-
【SDK API 发送】
|
|
1288
|
-
|
|
1289
|
-
通过 [V2TIMOfflinePushInfo](https://im.sdk.qcloud.com/doc/zh-cn/classcom_1_1tencent_1_1imsdk_1_1v2_1_1V2TIMOfflinePushInfo.html) 的 `ext` 属性携带跳转参数,再随消息一起发送。`setExt` 接收 `byte[]` 入参,业务自定义的 JSON 字符串需要先转成字节数组。
|
|
1290
|
-
|
|
1291
|
-
如果您接入了 TUIKit,TUIKit 内置的消息发送链路会自动用 `OfflinePushExtInfo` 组装 `ext`,无需手动设置。下方示例适用于自行调用 IM SDK 发送消息的场景。
|
|
1292
|
-
|
|
1293
|
-
【Java】
|
|
1294
|
-
``` java
|
|
1295
|
-
import android.util.Log;
|
|
1296
|
-
|
|
1297
|
-
import com.tencent.imsdk.v2.V2TIMManager;
|
|
1298
|
-
import com.tencent.imsdk.v2.V2TIMMessage;
|
|
1299
|
-
import com.tencent.imsdk.v2.V2TIMOfflinePushInfo;
|
|
1300
|
-
import com.tencent.imsdk.v2.V2TIMSendCallback;
|
|
1301
|
-
|
|
1302
|
-
V2TIMOfflinePushInfo pushInfo = new V2TIMOfflinePushInfo();
|
|
1303
|
-
pushInfo.setTitle("推送标题");
|
|
1304
|
-
pushInfo.setDesc("推送内容");
|
|
1305
|
-
// TODO: ext 由业务自定义,按需替换为您的目标页面、会话 ID 等参数。
|
|
1306
|
-
String ext = "{\"conversationID\":\"user_A\",\"conversationType\":1}";
|
|
1307
|
-
pushInfo.setExt(ext.getBytes());
|
|
1308
|
-
|
|
1309
|
-
V2TIMMessage message = V2TIMManager.getMessageManager().createTextMessage("Hello TIMPush");
|
|
1310
|
-
V2TIMManager.getMessageManager().sendMessage(
|
|
1311
|
-
message,
|
|
1312
|
-
"<TARGET_USER_ID>", // 单聊填对端 userID,群聊该参数填 null
|
|
1313
|
-
null, // 群聊填 groupID,单聊该参数填 null
|
|
1314
|
-
V2TIMMessage.V2TIM_PRIORITY_DEFAULT,
|
|
1315
|
-
false,
|
|
1316
|
-
pushInfo,
|
|
1317
|
-
new V2TIMSendCallback<V2TIMMessage>() {
|
|
1318
|
-
@Override
|
|
1319
|
-
public void onProgress(int progress) {}
|
|
1320
|
-
|
|
1321
|
-
@Override
|
|
1322
|
-
public void onSuccess(V2TIMMessage msg) {
|
|
1323
|
-
Log.d("TIMPush", ">>>>> sendMessage success, msgID = " + msg.getMsgID());
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
@Override
|
|
1327
|
-
public void onError(int code, String desc) {
|
|
1328
|
-
Log.e("TIMPush", ">>>>> sendMessage failed, code = " + code + ", desc = " + desc);
|
|
1329
|
-
}
|
|
1330
|
-
});
|
|
1331
|
-
```
|
|
1332
|
-
|
|
1333
|
-
【Kotlin】
|
|
1334
|
-
``` java
|
|
1335
|
-
import android.util.Log
|
|
1336
|
-
import com.tencent.imsdk.v2.V2TIMManager
|
|
1337
|
-
import com.tencent.imsdk.v2.V2TIMMessage
|
|
1338
|
-
import com.tencent.imsdk.v2.V2TIMOfflinePushInfo
|
|
1339
|
-
import com.tencent.imsdk.v2.V2TIMSendCallback
|
|
1340
|
-
|
|
1341
|
-
val pushInfo = V2TIMOfflinePushInfo()
|
|
1342
|
-
pushInfo.title = "推送标题"
|
|
1343
|
-
pushInfo.desc = "推送内容"
|
|
1344
|
-
// TODO: ext 由业务自定义,按需替换为您的目标页面、会话 ID 等参数。
|
|
1345
|
-
pushInfo.ext = "{\"conversationID\":\"user_A\",\"conversationType\":1}".toByteArray()
|
|
1346
|
-
|
|
1347
|
-
val message = V2TIMManager.getMessageManager().createTextMessage("Hello TIMPush")
|
|
1348
|
-
V2TIMManager.getMessageManager().sendMessage(
|
|
1349
|
-
message,
|
|
1350
|
-
"<TARGET_USER_ID>", // 单聊填对端 userID,群聊该参数填 null
|
|
1351
|
-
null, // 群聊填 groupID,单聊该参数填 null
|
|
1352
|
-
V2TIMMessage.V2TIM_PRIORITY_DEFAULT,
|
|
1353
|
-
false,
|
|
1354
|
-
pushInfo,
|
|
1355
|
-
object : V2TIMSendCallback<V2TIMMessage> {
|
|
1356
|
-
override fun onProgress(progress: Int) {}
|
|
1357
|
-
|
|
1358
|
-
override fun onSuccess(msg: V2TIMMessage) {
|
|
1359
|
-
Log.d("TIMPush", ">>>>> sendMessage success, msgID = ${msg.msgID}")
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
override fun onError(code: Int, desc: String?) {
|
|
1363
|
-
Log.e("TIMPush", ">>>>> sendMessage failed, code = $code, desc = $desc")
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
)
|
|
1367
|
-
```
|
|
1368
|
-
|
|
1369
|
-
#### **客户端注册监听并解析** `ext`
|
|
1370
|
-
|
|
1371
|
-
请在 `Application.onCreate()` 中调用 addPushListener 注册 `TIMPushListener`,并在 onNotificationClicked 中解析 `ext` 后跳转到业务页面。
|
|
1372
|
-
|
|
1373
|
-
以下示例只演示解析 `ext` 的核心逻辑,跳转部分用 `TODO` 占位,请按自身业务补充。如果您接入了 TUIKit 并使用 `OfflinePushExtInfo` 组装的 `ext`,可改为 `new Gson().fromJson(ext, OfflinePushExtInfo.class)` 解析后再跳转。
|
|
1374
|
-
|
|
1375
|
-
【Java】
|
|
1376
|
-
``` java
|
|
1377
|
-
import android.app.Application;
|
|
1378
|
-
import android.text.TextUtils;
|
|
1379
|
-
import android.util.Log;
|
|
1380
|
-
|
|
1381
|
-
import com.tencent.timpush.TIMPushListener;
|
|
1382
|
-
import com.tencent.timpush.TIMPushManager;
|
|
1383
|
-
|
|
1384
|
-
import org.json.JSONObject;
|
|
1385
|
-
|
|
1386
|
-
public class App extends Application {
|
|
1387
|
-
private static final String TAG = "TIMPush";
|
|
1388
|
-
|
|
1389
|
-
@Override
|
|
1390
|
-
public void onCreate() {
|
|
1391
|
-
super.onCreate();
|
|
1392
|
-
|
|
1393
|
-
TIMPushManager.getInstance().addPushListener(new TIMPushListener() {
|
|
1394
|
-
@Override
|
|
1395
|
-
public void onNotificationClicked(String ext) {
|
|
1396
|
-
Log.d(TAG, ">>>>> TIMPush notification clicked, ext = " + ext);
|
|
1397
|
-
|
|
1398
|
-
if (TextUtils.isEmpty(ext)) {
|
|
1399
|
-
return;
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
// 1. 解析 ext。JSON 结构由业务自定义,需与发送端约定一致。
|
|
1403
|
-
String conversationID;
|
|
1404
|
-
int conversationType;
|
|
1405
|
-
try {
|
|
1406
|
-
JSONObject json = new JSONObject(ext);
|
|
1407
|
-
conversationID = json.optString("conversationID");
|
|
1408
|
-
conversationType = json.optInt("conversationType");
|
|
1409
|
-
} catch (Exception e) {
|
|
1410
|
-
Log.e(TAG, ">>>>> parse ext failed: " + e.getMessage());
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
// 2. TODO: 根据业务字段跳转到目标页面。
|
|
1415
|
-
// 若使用了 Chat / TUIKit,建议在用户登录成功后再跳转;
|
|
1416
|
-
// 冷启动场景可先把参数缓存起来,登录回调中再跳转。
|
|
1417
|
-
}
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
```
|
|
1422
|
-
|
|
1423
|
-
【Kotlin】
|
|
1424
|
-
``` java
|
|
1425
|
-
import android.app.Application
|
|
1426
|
-
import android.text.TextUtils
|
|
1427
|
-
import android.util.Log
|
|
1428
|
-
|
|
1429
|
-
import com.tencent.timpush.TIMPushListener
|
|
1430
|
-
import com.tencent.timpush.TIMPushManager
|
|
1431
|
-
|
|
1432
|
-
import org.json.JSONObject
|
|
1433
|
-
|
|
1434
|
-
class App : Application() {
|
|
1435
|
-
override fun onCreate() {
|
|
1436
|
-
super.onCreate()
|
|
1437
|
-
|
|
1438
|
-
TIMPushManager.getInstance().addPushListener(object : TIMPushListener() {
|
|
1439
|
-
override fun onNotificationClicked(ext: String?) {
|
|
1440
|
-
Log.d("TIMPush", ">>>>> TIMPush notification clicked, ext = $ext")
|
|
1441
|
-
|
|
1442
|
-
if (TextUtils.isEmpty(ext)) return
|
|
1443
|
-
|
|
1444
|
-
// 1. 解析 ext。JSON 结构由业务自定义,需与发送端约定一致。
|
|
1445
|
-
val conversationID: String
|
|
1446
|
-
val conversationType: Int
|
|
1447
|
-
try {
|
|
1448
|
-
val json = JSONObject(ext)
|
|
1449
|
-
conversationID = json.optString("conversationID")
|
|
1450
|
-
conversationType = json.optInt("conversationType")
|
|
1451
|
-
} catch (e: Exception) {
|
|
1452
|
-
Log.e("TIMPush", ">>>>> parse ext failed: ${e.message}")
|
|
1453
|
-
return
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
// 2. TODO: 根据业务字段跳转到目标页面。
|
|
1457
|
-
// 若使用了 Chat / TUIKit,建议在用户登录成功后再跳转;
|
|
1458
|
-
// 冷启动场景可先把参数缓存起来,登录回调中再跳转。
|
|
1459
|
-
}
|
|
1460
|
-
})
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
```
|
|
1464
|
-
|
|
1465
|
-
**验证**:点击通知后 `onNotificationClicked` 被调用,且 `ext` 内容与发送时设置的一致。
|
|
1466
|
-
|
|
1467
|
-
> **说明:**
|
|
1468
|
-
> 旧版本工程中可能仍使用 `TUICore.registerEvent` 回调或 `LocalBroadcastManager` 广播处理点击通知。这两种方式在当前版本仍可工作,但新接入用户建议优先使用 `addPushListener`。如需从旧方案迁移,删除旧的事件注册或广播注册代码,改为在 `Application.onCreate()` 中调用 `addPushListener` 即可,回调中获取到的 `ext` 内容与旧方案一致。
|
|
1469
|
-
>
|
|
492
|
+
如果要实现自定义点击 Push 消息跳转,参考文档 自定义点击推送跳转 处理。
|
|
1470
493
|
|
|
1471
494
|
## 接入排查
|
|
1472
495
|
|