6. 消息同步

监听目标第三方软件的消息通知,同步消息到设备端

6.1. 推送消息

监听到目标第三方软件的消息通知后,推送消息到设备端

示例代码

//WatchManager是WatchOpImpl的子类,须在1.3配置好sdk
WatchManager watchManager = WatchManager.getInstance();
//模拟收到微信消息
String appName = HealthConstant.PACKAGE_NAME_WECHAT;
NotificationMsg msg = new NotificationMsg()
        .setAppName(appName)
        .setFlag(NotificationHelper.getNotificationFlag(appName))
        .setContent("帅小伙:[1条] 你好,欢迎使用健康助手,乐享运动,助力健康!")
        .setTitle("测试消息")
        .setTime(time)
        .setOp(NotificationMsg.OP_PUSH);
watchManager.pushMessageInfo(msg, new OnWatchOpCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
            //回调成功
    }

    @Override
    public void onFailed(BaseError error) {
        //回调失败
        //error: 错误信息
    }
});

Important

  1. 需要获取监听应用通知的权限

  2. 需要判断应用是否打开通知功能

6.1.1. 信息说明

信息类型表

Type

name

Value

0

时间戳

时间戳(4Bytes, 参考运动记录的时间戳格式 时间结构(4Bytes))

1

包名

最大限制范围: 31 Bytes

2

应用标识

Flag(1 Byte):
0: 默认图标
1: 短信图标
2: 微信图标
3: QQ图标
4: 钉钉图标

3

标题

最大限制范围: 36 Bytes

4

内容

最大限制范围: 133 ~ 439 Bytes, 由固件决定

6.2. 删除消息

监听到系统清除消息通知后,通知设备端删除该消息

示例代码

//WatchManager是WatchOpImpl的子类,须在1.3配置好sdk
WatchManager watchManager = WatchManager.getInstance();
//模拟撤销微信消息
String appName = HealthConstant.PACKAGE_NAME_WECHAT;
NotificationMsg msg = new NotificationMsg()
        .setAppName(appName)
        .setFlag(NotificationHelper.getNotificationFlag(appName))
        .setTime(time)
        .setOp(NotificationMsg.OP_REMOVE);
watchManager.removeMessageInfo(msg, new OnWatchOpCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //回调成功
    }

    @Override
    public void onFailed(BaseError error) {
        //回调失败
        //error: 错误信息
    }
});

Important

  1. 需要获取监听应用通知的权限