7.3 场景解析
以下几种普通推送结合辅助弹窗推送的场景,帮助您快速理解辅助弹窗功能的配置。
客户端配置
客户端有Main、Second两个Activity,MainActivity为App打开主页面,SecondActivity extends AndroidPopupActivity;
- [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]MyMessageReceiver[backcolor=transparent] [backcolor=transparent]extends[backcolor=transparent] [backcolor=transparent]MessageReceiver[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]/**
- [backcolor=transparent] * 推送通知的回调方法
- [backcolor=transparent] * @param context
- [backcolor=transparent] * @param title
- [backcolor=transparent] * @param summary
- [backcolor=transparent] * @param extraMap
- [backcolor=transparent] */
- [backcolor=transparent] [backcolor=transparent]@Override
- [backcolor=transparent] [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onNotification[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent]>[backcolor=transparent] extraMap[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]d[backcolor=transparent]([backcolor=transparent]TAG[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"Receive notification, title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] title [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", content: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] summary [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", extraMap: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] extraMap[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
- [backcolor=transparent]package[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]push[backcolor=transparent].[backcolor=transparent]testdemo[backcolor=transparent];
- [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]MainActivity[backcolor=transparent] [backcolor=transparent]extends[backcolor=transparent] [backcolor=transparent]Activity[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]@Override
- [backcolor=transparent] [backcolor=transparent]protected[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onCreate[backcolor=transparent]([backcolor=transparent]Bundle[backcolor=transparent] savedInstanceState[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]d[backcolor=transparent]([backcolor=transparent]TAG[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"Main"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
- [backcolor=transparent]package[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]push[backcolor=transparent].[backcolor=transparent]testdemo[backcolor=transparent];
- [backcolor=transparent]import[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]sdk[backcolor=transparent].[backcolor=transparent]android[backcolor=transparent].[backcolor=transparent]push[backcolor=transparent].[backcolor=transparent]AndroidPopupActivity[backcolor=transparent];
- [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]SecondActivity[backcolor=transparent] [backcolor=transparent]extends[backcolor=transparent] [backcolor=transparent]AndroidPopupActivity[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]/**
- [backcolor=transparent] * 辅助弹窗指定打开Activity回调
- [backcolor=transparent] * @param title 标题
- [backcolor=transparent] * @param content 内容
- [backcolor=transparent] * @param extraMap 额外参数
- [backcolor=transparent] */
- [backcolor=transparent] [backcolor=transparent]@Override
- [backcolor=transparent] [backcolor=transparent]protected[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onSysNoticeOpened[backcolor=transparent]([backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] content[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent]>[backcolor=transparent] extraMap[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]d[backcolor=transparent]([backcolor=transparent]TAG[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"Receive XiaoMi notification, title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] title [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", content: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] content [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", extraMap: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] extraMap[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
场景1:普通推送打开App + 辅助弹窗
服务端配置如下:
- [backcolor=transparent]PushRequest[backcolor=transparent] pushRequest [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]PushRequest[backcolor=transparent]();
- [backcolor=transparent]// 其余设置省略
- [backcolor=transparent]// ...
- [backcolor=transparent]// 0:表示消息(默认为0), 1:表示通知
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setType[backcolor=transparent]([backcolor=transparent]1[backcolor=transparent]);
- [backcolor=transparent]// 标题
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTitle[backcolor=transparent]([backcolor=transparent]"hello"[backcolor=transparent]);
- [backcolor=transparent]// 内容
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setBody[backcolor=transparent]([backcolor=transparent]"PushRequest body"[backcolor=transparent]);
- [backcolor=transparent]// 点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidOpenType[backcolor=transparent]([backcolor=transparent]"APPLICATION"[backcolor=transparent]);
- [backcolor=transparent]// 设置辅助弹窗打开Activity
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupActivity[backcolor=transparent]([backcolor=transparent]"com.alibaba.push.testdemo.SecondActivity"[backcolor=transparent]);
- [backcolor=transparent]// 设置辅助弹窗通知标题
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupTitle[backcolor=transparent]([backcolor=transparent]"hello2"[backcolor=transparent]);
- [backcolor=transparent]// 设置辅助弹窗通知内容
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupBody[backcolor=transparent]([backcolor=transparent]"PushRequest body2"[backcolor=transparent]);
- [backcolor=transparent]// 设定android类型设备通知的扩展属性
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidExtParameters[backcolor=transparent]([backcolor=transparent]"{\"k1\":\"android\",\"k2\":\"v2\"}"[backcolor=transparent]);
推送结果:
非小米、华为设备和在线小米、华为设备收到普通推送通道弹出的通知,点击后打开App,进入首页MainActivity,如果设备在前台,保持当前界面不变;- onNotification()回调输出Receive notification, title: hello, content: PushRequest body, extraMap: {k1=android, k2=v2};
清理进程后的小米、华为设备
- 辅助弹窗通道弹出通知,点击后跳转到SecondActivity;
- onSysNoticeOpened()回调输出Receive XiaoMi notification, title: hello2, content: PushRequest body2, extraMap: {k1=android, k2=v2};
场景2:普通推送打开Activity + 辅助弹窗
服务端配置如下:
- [backcolor=transparent]PushRequest[backcolor=transparent] pushRequest [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]PushRequest[backcolor=transparent]();
- [backcolor=transparent]// 其余设置省略
- [backcolor=transparent]// ...
- [backcolor=transparent]// 0:表示消息(默认为0), 1:表示通知
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setType[backcolor=transparent]([backcolor=transparent]1[backcolor=transparent]);
- [backcolor=transparent]// 标题
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTitle[backcolor=transparent]([backcolor=transparent]"hello"[backcolor=transparent]);
- [backcolor=transparent]// 内容
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setBody[backcolor=transparent]([backcolor=transparent]"PushRequest body"[backcolor=transparent]);
- [backcolor=transparent]// 点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidOpenType[backcolor=transparent]([backcolor=transparent]"ACTIVITY"[backcolor=transparent]);
- [backcolor=transparent]// 指定普通推送要打开的Activity
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidActivity[backcolor=transparent]([backcolor=transparent]"com.alibaba.push.testdemo.SecondActivity"[backcolor=transparent]);
- [backcolor=transparent]// 设置辅助弹窗打开Activity
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupActivity[backcolor=transparent]([backcolor=transparent]"com.alibaba.push.testdemo.SecondActivity"[backcolor=transparent]);
- [backcolor=transparent]// 设置辅助弹窗通知标题
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupTitle[backcolor=transparent]([backcolor=transparent]"hello2"[backcolor=transparent]);
- [backcolor=transparent]// 设置辅助弹窗通知内容
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupBody[backcolor=transparent]([backcolor=transparent]"PushRequest body2"[backcolor=transparent]);
- [backcolor=transparent]// 设定android类型设备通知的扩展属性
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidExtParameters[backcolor=transparent]([backcolor=transparent]"{\"k1\":\"android\",\"k2\":\"v2\"}"[backcolor=transparent]);
推送结果:
非小米、华为设备和在线小米、华为设备收到普通推送通道弹出的通知,点击后跳转到SecondActivity;- onNotification()回调输出Receive notification, title: hello, content: PushRequest body, extraMap: {k1=android, k2=v2};
清理进程后的小米、华为设备
- 辅助弹窗通道弹出通知,点击后跳转到SecondActivity;
- onSysNoticeOpened()回调输出Receive XiaoMi notification, title: hello2, content: PushRequest body2, extraMap: {k1=android, k2=v2};