开发者社区> 问答> 正文

如何实现移动推送辅助通道配置?(3)



7.3 场景解析


以下几种普通推送结合辅助弹窗推送的场景,帮助您快速理解辅助弹窗功能的配置。

客户端配置


客户端有Main、Second两个Activity,MainActivity为App打开主页面,SecondActivity extends AndroidPopupActivity;

  • 普通通知回调配置:
  1. [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]{
  2. [backcolor=transparent]  [backcolor=transparent]/**
  3. [backcolor=transparent]  * 推送通知的回调方法
  4. [backcolor=transparent]  * @param context
  5. [backcolor=transparent]  * @param title
  6. [backcolor=transparent]  * @param summary
  7. [backcolor=transparent]  * @param extraMap
  8. [backcolor=transparent]  */
  9. [backcolor=transparent]  [backcolor=transparent]@Override
  10. [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]{
  11. [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]);
  12. [backcolor=transparent]  [backcolor=transparent]}
  13. [backcolor=transparent]}
  • MainActivity定义:
  1. [backcolor=transparent]package[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]push[backcolor=transparent].[backcolor=transparent]testdemo[backcolor=transparent];
  2. [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]{
  3. [backcolor=transparent]  [backcolor=transparent]@Override
  4. [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]{
  5. [backcolor=transparent]    [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]d[backcolor=transparent]([backcolor=transparent]TAG[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"Main"[backcolor=transparent]);
  6. [backcolor=transparent]  [backcolor=transparent]}
  7. [backcolor=transparent]}
  • SecondActivity定义:
  1. [backcolor=transparent]package[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]push[backcolor=transparent].[backcolor=transparent]testdemo[backcolor=transparent];
  2. [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];
  3. [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]{
  4. [backcolor=transparent]  [backcolor=transparent]/**
  5. [backcolor=transparent]   * 辅助弹窗指定打开Activity回调
  6. [backcolor=transparent]   * @param title     标题
  7. [backcolor=transparent]   * @param content   内容
  8. [backcolor=transparent]   * @param extraMap  额外参数
  9. [backcolor=transparent]   */
  10. [backcolor=transparent]  [backcolor=transparent]@Override
  11. [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]{
  12. [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]);
  13. [backcolor=transparent]  [backcolor=transparent]}
  14. [backcolor=transparent]}


场景1:普通推送打开App + 辅助弹窗


服务端配置如下:
  1. [backcolor=transparent]PushRequest[backcolor=transparent] pushRequest [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]PushRequest[backcolor=transparent]();
  2. [backcolor=transparent]// 其余设置省略
  3. [backcolor=transparent]// ...
  4. [backcolor=transparent]// 0:表示消息(默认为0), 1:表示通知
  5. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setType[backcolor=transparent]([backcolor=transparent]1[backcolor=transparent]);
  6. [backcolor=transparent]// 标题
  7. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTitle[backcolor=transparent]([backcolor=transparent]"hello"[backcolor=transparent]);
  8. [backcolor=transparent]// 内容
  9. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setBody[backcolor=transparent]([backcolor=transparent]"PushRequest body"[backcolor=transparent]);
  10. [backcolor=transparent]// 点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
  11. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidOpenType[backcolor=transparent]([backcolor=transparent]"APPLICATION"[backcolor=transparent]);
  12. [backcolor=transparent]// 设置辅助弹窗打开Activity
  13. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupActivity[backcolor=transparent]([backcolor=transparent]"com.alibaba.push.testdemo.SecondActivity"[backcolor=transparent]);
  14. [backcolor=transparent]// 设置辅助弹窗通知标题
  15. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupTitle[backcolor=transparent]([backcolor=transparent]"hello2"[backcolor=transparent]);
  16. [backcolor=transparent]// 设置辅助弹窗通知内容
  17. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupBody[backcolor=transparent]([backcolor=transparent]"PushRequest body2"[backcolor=transparent]);
  18. [backcolor=transparent]// 设定android类型设备通知的扩展属性
  19. [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 + 辅助弹窗


服务端配置如下:
  1. [backcolor=transparent]PushRequest[backcolor=transparent] pushRequest [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]PushRequest[backcolor=transparent]();
  2. [backcolor=transparent]// 其余设置省略
  3. [backcolor=transparent]// ...
  4. [backcolor=transparent]// 0:表示消息(默认为0), 1:表示通知
  5. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setType[backcolor=transparent]([backcolor=transparent]1[backcolor=transparent]);
  6. [backcolor=transparent]// 标题
  7. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTitle[backcolor=transparent]([backcolor=transparent]"hello"[backcolor=transparent]);
  8. [backcolor=transparent]// 内容
  9. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setBody[backcolor=transparent]([backcolor=transparent]"PushRequest body"[backcolor=transparent]);
  10. [backcolor=transparent]// 点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
  11. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidOpenType[backcolor=transparent]([backcolor=transparent]"ACTIVITY"[backcolor=transparent]);
  12. [backcolor=transparent]// 指定普通推送要打开的Activity
  13. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidActivity[backcolor=transparent]([backcolor=transparent]"com.alibaba.push.testdemo.SecondActivity"[backcolor=transparent]);
  14. [backcolor=transparent]// 设置辅助弹窗打开Activity
  15. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupActivity[backcolor=transparent]([backcolor=transparent]"com.alibaba.push.testdemo.SecondActivity"[backcolor=transparent]);
  16. [backcolor=transparent]// 设置辅助弹窗通知标题
  17. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupTitle[backcolor=transparent]([backcolor=transparent]"hello2"[backcolor=transparent]);
  18. [backcolor=transparent]// 设置辅助弹窗通知内容
  19. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupBody[backcolor=transparent]([backcolor=transparent]"PushRequest body2"[backcolor=transparent]);
  20. [backcolor=transparent]// 设定android类型设备通知的扩展属性
  21. [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};

展开
收起
猫饭先生 2017-10-23 11:03:44 1635 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
内容驱动游戏分发 立即下载
动态、高效,蚂蚁动态卡片的内核逻辑 立即下载
“静态调用链路发现”应用场景分析及实践探索 立即下载