开发者社区> 问答> 正文

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



6. 在日志中查看初始化情况


华为通道初始化成功,可以看到以下日志:

  1. [backcolor=transparent]11[backcolor=transparent]-[backcolor=transparent]11[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]21[backcolor=transparent]:[backcolor=transparent]33.671[backcolor=transparent]  [backcolor=transparent]30248[backcolor=transparent]-[backcolor=transparent]30324[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]HuaWeiRegister[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]HuaWeiRegister[backcolor=transparent] checkDevice flag[backcolor=transparent]=[backcolor=transparent]true [backcolor=transparent]//确认是华为的手机
  2. [backcolor=transparent]11[backcolor=transparent]-[backcolor=transparent]11[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]21[backcolor=transparent]:[backcolor=transparent]33.674[backcolor=transparent]  [backcolor=transparent]30248[backcolor=transparent]-[backcolor=transparent]30324[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]HuaWeiRegister[backcolor=transparent][backcolor=transparent] [backcolor=transparent]Register[backcolor=transparent] huawei push[backcolor=transparent]............[backcolor=transparent]      [backcolor=transparent]//开始注册华为手机
  3. [backcolor=transparent]11[backcolor=transparent]-[backcolor=transparent]11[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]21[backcolor=transparent]:[backcolor=transparent]33.714[backcolor=transparent]  [backcolor=transparent]29643[backcolor=transparent]-[backcolor=transparent]30328[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]HuaWeiRegister[backcolor=transparent][backcolor=transparent] huawei register success[backcolor=transparent][backcolor=transparent]token [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]08657430243125472000000411000001
  4. [backcolor=transparent]11[backcolor=transparent]-[backcolor=transparent]11[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]21[backcolor=transparent]:[backcolor=transparent]33.714[backcolor=transparent]  [backcolor=transparent]29643[backcolor=transparent]-[backcolor=transparent]30328[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]HuaWeiRegister[backcolor=transparent][backcolor=transparent] report huaweiPushId intent[backcolor=transparent]...[backcolor=transparent]         [backcolor=transparent]//完成华为注册和信息上报

小米通道初始化成功,可以看到以下日志:
  1. [backcolor=transparent]12[backcolor=transparent]-[backcolor=transparent]09[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]20[backcolor=transparent]:[backcolor=transparent]39.710[backcolor=transparent] [backcolor=transparent]19566[backcolor=transparent]-[backcolor=transparent]19566[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]MiPushRegister[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]MiPushRegister[backcolor=transparent] checkDevice flag[backcolor=transparent]=[backcolor=transparent]true [backcolor=transparent]//确认是小米的手机
  2. [backcolor=transparent]12[backcolor=transparent]-[backcolor=transparent]09[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]20[backcolor=transparent]:[backcolor=transparent]39.712[backcolor=transparent] [backcolor=transparent]19566[backcolor=transparent]-[backcolor=transparent]19566[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]MiPushRegister[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]Register[backcolor=transparent] mipush[backcolor=transparent].[backcolor=transparent]                     [backcolor=transparent]//开始注册小米
  3. [backcolor=transparent]12[backcolor=transparent]-[backcolor=transparent]09[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]20[backcolor=transparent]:[backcolor=transparent]40.596[backcolor=transparent] [backcolor=transparent]19566[backcolor=transparent]-[backcolor=transparent]19733[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx E[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]MiPushRegister[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]XiaoMi[backcolor=transparent] register success[backcolor=transparent].[backcolor=transparent]             [backcolor=transparent]//小米注册成功[backcolor=transparent] regid[backcolor=transparent]=[backcolor=transparent]d[backcolor=transparent]//[backcolor=transparent]igwEhgBGCI2TG6lWqlCesc0I6xE1wUhNCBXQ8uNOi[backcolor=transparent]/[backcolor=transparent]dDZioYXVysbrVrvRmyEVPn9nWz92D28IzYbA1RzoGDyTzYZwXKfBHEQkrey4G8[backcolor=transparent]=

GCM/FCM通道初始化成功,可以看到以下日志:
  1. [backcolor=transparent]05[backcolor=transparent]-[backcolor=transparent]19[backcolor=transparent] [backcolor=transparent]19[backcolor=transparent]:[backcolor=transparent]18[backcolor=transparent]:[backcolor=transparent]44.530[backcolor=transparent] [backcolor=transparent]19153[backcolor=transparent]-[backcolor=transparent]19177[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx D[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]GcmRegister[backcolor=transparent]:[backcolor=transparent] token from register[backcolor=transparent]:[backcolor=transparent] eWIXLYCNP0Q[backcolor=transparent]:[backcolor=transparent]APA91bFUAgxj6XYf5okyoCBnRPw1UwITndzXrvPDgbdI2N44PYm17hFEBiNXNQJrJ8bOG_xjw3c3UPDAhzNMTLNjlAKcjUanKyLA6E3k4wEmgZuhgUT02UMmMvH2LVA1L2Z4[backcolor=transparent]-[backcolor=transparent]l[backcolor=transparent]-[backcolor=transparent]cT_Ug

收到小米通道下行的消息:(需要将sdk日志等级设置到DEBUG)
  1. [backcolor=transparent]12[backcolor=transparent]-[backcolor=transparent]09[backcolor=transparent] [backcolor=transparent]22[backcolor=transparent]:[backcolor=transparent]24[backcolor=transparent]:[backcolor=transparent]34.065[backcolor=transparent] [backcolor=transparent]19566[backcolor=transparent]-[backcolor=transparent]25042[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]xxx D[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]MiPushReceiver[backcolor=transparent]:[backcolor=transparent] onReceiveMessage[backcolor=transparent],[backcolor=transparent]msg[backcolor=transparent]=[{[backcolor=transparent]"f"[backcolor=transparent]:[backcolor=transparent]262[backcolor=transparent],[backcolor=transparent]"b"[backcolor=transparent]:[backcolor=transparent]"{\"content\"\ ... ... ,"[backcolor=transparent]i[backcolor=transparent]":"[backcolor=transparent]f__[backcolor=transparent]-[backcolor=transparent]rnje3_OH74gE[backcolor=transparent]|[backcolor=transparent]VG0g3kwMnGADAGrXZku1FFW5[backcolor=transparent]"}]

收到GCM/FCM通道下发的消息:
  1. [backcolor=transparent]05[backcolor=transparent]-[backcolor=transparent]19[backcolor=transparent] [backcolor=transparent]19[backcolor=transparent]:[backcolor=transparent]20[backcolor=transparent]:[backcolor=transparent]04.900[backcolor=transparent] [backcolor=transparent]19153[backcolor=transparent]-[backcolor=transparent]20391[backcolor=transparent]/[backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].[backcolor=transparent]push2 D[backcolor=transparent]/[backcolor=transparent]MPS[backcolor=transparent]:[backcolor=transparent]GcmRegister[backcolor=transparent]:[backcolor=transparent] onReceiveMessage payload msg[backcolor=transparent]:[......]

若小米通道注册失败(未看到小米注册成功日志),请查看系统日志(logcat设置NoFilters),以PushService|BroadcastQueue为正则式进行过滤,示例如下图:

  • MiPushBroadcastReceiver未配置:

[backcolor=transparent]注:如果控制台配置了小米/华为的信息,app需要加对应的jar包依赖,不然会有crash的风险。

7. 辅助弹窗

  • 当前部分国产品牌设备管控严格,接入推送功能的App进程在后台被清理后,收不到推送通知;接入辅助弹窗后,可以借助对应品牌的系统通道,保证App后台被清理后,仍能收到推送通知;
  • 当前辅助弹窗已接入小米、华为(小米辅助弹窗:v2.3.0及以上支持;华为辅助弹窗:v3.0.8及以上支持);
  • 当前华为辅助弹窗仅支持Emotion UI(华为定制ROM)4.1级以上版本的设备;


7.1 客户端

  • 该功能的使用需要接入推送辅助通道,确保使用最新的辅助通道扩展包,具体参考上文;
  • 辅助弹窗送达的通知展示效果,和普通通知相同;
  • 服务端指定辅助弹窗通道推送时,一定要指定通知点击后要打开的Activity,该Activity需继承自抽象类AndroidPopupActivity(MiPushSystemNotificationActivity已废弃,小米弹窗、华为弹窗统一继承AndroidPopupActivity),否则无法获取到通知的相关信息,并且会影响通知到达率的统计;
  • AndroidPopupActivity中提供抽象方法onSysNoticeOpened(),实现该方法后可获取到辅助弹窗通知的标题、内容和额外参数,在通知点击时触发,原本的通知回调onNotification()和onNotificationOpened()不适用于辅助弹窗;

  • 指定打开的托管弹窗Activity在AndroidManifest.xml中注册时需要声明属性:android:exported=true

  • 接入如下所示:
  1. [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];
  2. [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]PopupPushActivity[backcolor=transparent] [backcolor=transparent]extends[backcolor=transparent] [backcolor=transparent]AndroidPopupActivity[backcolor=transparent] [backcolor=transparent]{
  3. [backcolor=transparent]    [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]final[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] TAG [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"PopupPushActivity"[backcolor=transparent];
  4. [backcolor=transparent]    [backcolor=transparent]@Override
  5. [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]{
  6. [backcolor=transparent]        [backcolor=transparent]super[backcolor=transparent].[backcolor=transparent]onCreate[backcolor=transparent]([backcolor=transparent]savedInstanceState[backcolor=transparent]);
  7. [backcolor=transparent]    [backcolor=transparent]}
  8. [backcolor=transparent]    [backcolor=transparent]/**
  9. [backcolor=transparent]     * 实现通知打开回调方法,获取通知相关信息
  10. [backcolor=transparent]     * @param title     标题
  11. [backcolor=transparent]     * @param summary   内容
  12. [backcolor=transparent]     * @param extMap    额外参数
  13. [backcolor=transparent]     */
  14. [backcolor=transparent]    [backcolor=transparent]@Override
  15. [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] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent]>[backcolor=transparent] extMap[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  16. [backcolor=transparent]        [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]d[backcolor=transparent]([backcolor=transparent]"OnMiPushSysNoticeOpened, 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]", extMap: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] extMap[backcolor=transparent]);
  17. [backcolor=transparent]    [backcolor=transparent]}
  18. [backcolor=transparent]}


7.2 服务端

  • OpenAPI 2.0的推送高级接口提供了AndroidPopupActivity、AndroidPopupTitle和AndroidPopupBody三个参数,分别用于设置辅助弹窗通知打开时跳转的Activity、通知标题以及通知内容(注意:StoreOffline参数也需要设置为true);
  • 辅助弹窗仅对后台进程被清理的小米/华为设备生效,对非小米/华为设备和在线的小米/华为设备不生效;
  • 当辅助弹窗生效时,推送接口的Title、Body、AndroidActivity以及额外参数设置中的功能性设置(如声音、震动等)都不起作用;
    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]dateFormat[backcolor=transparent].[backcolor=transparent]format[backcolor=transparent]([backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]Date[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]// 额外参数
    11. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidExtParameters[backcolor=transparent]([backcolor=transparent]"{\"k1\":\"android\",\"k2\":\"v2\"}"[backcolor=transparent]);
    12. [backcolor=transparent]// 设置辅助弹窗打开Activity
    13. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupActivity[backcolor=transparent]([backcolor=transparent]"*****"[backcolor=transparent]);
    14. [backcolor=transparent]// 设置辅助弹窗通知标题
    15. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupTitle[backcolor=transparent]([backcolor=transparent]"*****"[backcolor=transparent]);
    16. [backcolor=transparent]// 设置辅助弹窗通知内容
    17. [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidPopupBody[backcolor=transparent]([backcolor=transparent]"*****"[backcolor=transparent]);

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

相关电子书

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