Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
xugenyuan
2024-05-29 19:32:07 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
860293cc4453a99bbde7c319cba6f2db1c359c27
860293cc
1 parent
ef9828ad
ref |> 调试个推推送,目前仅能收到后台透传消息,这里先展示在系统推送通知栏里
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
2 deletions
sight_harmony/features/wdHwAbility/src/main/ets/getuiPush/GetuiPush.ets
sight_harmony/features/wdHwAbility/src/main/ets/getuiPush/PushContentParser.ets
sight_harmony/features/wdHwAbility/src/main/ets/getuiPush/PushTransmitMessageBean.ets
sight_harmony/features/wdHwAbility/src/main/ets/getuiPush/GetuiPush.ets
View file @
860293c
...
...
@@ -8,10 +8,14 @@ import PushManager, {
import { AppUtils, DeviceUtil, EmitterEventId, EmitterUtils, Logger, SPHelper } from 'wdKit/Index';
import { HostEnum, HostManager, HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index';
import { notificationManager } from '@kit.NotificationKit';
import { BusinessError } from '@kit.BasicServicesKit';
import {
AsyncCallback,
BusinessError } from '@kit.BasicServicesKit';
import { SpConstants } from 'wdConstant/Index';
import { PushContentBean, PushContentParser } from './PushContentParser';
import { ParamType, Tracking } from 'wdTracking/Index';
import { PushTransmitMessageBean, PushTransmitMessagePayloadBean } from './PushTransmitMessageBean';
import { JSON } from '@kit.ArkTS';
import wantAgent from '@ohos.app.ability.wantAgent';
import { WantAgent } from '@ohos.app.ability.wantAgent';
const TAG = "GetuiPush"
...
...
@@ -209,7 +213,11 @@ export class GetuiPush {
return
}
if (this.lastPushContent.online) {
if (this.lastPushContent.want) {
if (this.lastPushContent.localNotify == true) {
Logger.debug(TAG, "推送 回执???: " + this.lastPushContent.want)
let gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了
PushManager.sendFeedbackMessage(this.lastPushContent.messageId || "", this.lastPushContent.taskId || "", gtactionid)
} else if (this.lastPushContent.want) {
Logger.debug(TAG, "推送 回执: " + this.lastPushContent.want)
PushManager.setClickWant(this.lastPushContent.want)
}
...
...
@@ -325,6 +333,81 @@ export class GetuiPush {
// */
// int gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了
// boolean result = PushManager.sendFeedbackMessage(taskid, messageid, gtactionid);
this.sendLocalNotification(message)
}
private sendLocalNotification(message: GTTransmitMessage) {
let jsonMsgObj = JSON.parse(message.payload) as PushTransmitMessageBean
if (!jsonMsgObj) {
return
}
if (jsonMsgObj && jsonMsgObj.payload) {
jsonMsgObj.payloadObj = JSON.parse(jsonMsgObj.payload) as PushTransmitMessagePayloadBean
}
let pushLink = jsonMsgObj.payloadObj?.pushLink || ""
let params: Record<string, string> = {
"title": jsonMsgObj.title,
"content": jsonMsgObj.body,
"pushLink": pushLink,
"taskid": message.taskId,
"messageId": message.messageId,
"gtTransmitMsgLocalNotify": "1",
}
this.getWantAgent(params, (error, want) => {
if (error) {
return
}
let notificationRequest: notificationManager.NotificationRequest = {
id: Date.now(),
content: {
notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
title: jsonMsgObj.title,
text: jsonMsgObj.body,
}
},
notificationSlotType: notificationManager.SlotType.CONTENT_INFORMATION,
wantAgent:want,
};
notificationManager.publish(notificationRequest).then(() => {
Logger.debug(TAG, "本地发送系统通知完成")
}).catch((err: BusinessError) => {
Logger.debug(TAG, "本地发送系统通知失败:" + JSON.stringify(err))
});
})
}
private getWantAgent(parameters:Record<string, string>, callback: AsyncCallback<WantAgent>) {
// 通过WantAgentInfo的operationType设置动作类型
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [
{
deviceId: '',
bundleName: 'com.peopledailychina.hosactivity',
abilityName: 'EntryAbility',
action: 'com.test.pushaction',
entities: [],
uri: "rmrbapp://rmrb.app:8080/openwith",
parameters: parameters
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo, (err:BusinessError, data:WantAgent) => {
if (err) {
Logger.error(TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`)
}
if (callback) {
callback(err, data)
}
});
}
private uploadPushInfo(cid: string) {
...
...
sight_harmony/features/wdHwAbility/src/main/ets/getuiPush/PushContentParser.ets
View file @
860293c
...
...
@@ -11,6 +11,12 @@ export interface PushContentBean {
pushLink?: string // 解析want,对应pushLink参数
notifyTitle?: string
notifyContent?: string
// 透传消息发送的本地测试通知
localNotify?:boolean
taskId?: string
messageId?: string
}
/*
...
...
@@ -18,6 +24,8 @@ export interface PushContentBean {
* */
export class PushContentParser {
private static LAUNCH_PARAM_GETUI_TRANSMIT_MSG_LOCAL_NOTIFY = "gtTransmitMsgLocalNotify"
private static LAUNCH_PARAM_GETUI_DATA = "gtdata"
private static LAUNCH_PARAM_GETUI_TASKID = "taskid"
private static LAUNCH_PARAM_GETUI_NOTIFYID = "_push_notifyid"
...
...
@@ -116,6 +124,21 @@ export class PushContentParser {
}
}
// 本地发送的测试通知
if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_TRANSMIT_MSG_LOCAL_NOTIFY]) {
if (want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK]) {
let pushLink = want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK] as string
return {
isPush: true, online: true, pushLink: pushLink, want: want,
notifyTitle: want.parameters["title"] as string,
notifyContent: want.parameters["content"] as string,
localNotify: true,
taskId: want.parameters["taskId"] as string,
messageId: want.parameters["messageId"] as string,
}
}
}
return {
isPush: false, online: false
}
...
...
sight_harmony/features/wdHwAbility/src/main/ets/getuiPush/PushTransmitMessageBean.ets
0 → 100644
View file @
860293c
export interface PushTransmitMessageBean {
body: string
title: string
clickType: string
payload: string
payloadObj?: PushTransmitMessagePayloadBean
}
export interface PushTransmitMessagePayloadBean {
pushLink: string
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment