Android SDK 3.0配置如何实现?(3)-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

Android SDK 3.0配置如何实现?(3)

2017-10-23 10:56:02 1310 0


3.4 消息接收Receiver配置


创建消息接收Receiver,继承自com.alibaba.sdk.android.push.MessageReceiver,并在对应回调中添加业务处理逻辑,可参考以下代码:
  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]// 消息接收部分的LOG_TAG
  3. [backcolor=transparent]    [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]final[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] REC_TAG [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"receiver"[backcolor=transparent];
  4. [backcolor=transparent]    [backcolor=transparent]@Override
  5. [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]{
  6. [backcolor=transparent]        [backcolor=transparent]// TODO 处理推送通知
  7. [backcolor=transparent]        [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]e[backcolor=transparent]([backcolor=transparent]"MyMessageReceiver"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"Receive notification, title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] title [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", summary: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] summary [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", extraMap: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] extraMap[backcolor=transparent]);
  8. [backcolor=transparent]    [backcolor=transparent]}
  9. [backcolor=transparent]    [backcolor=transparent]@Override
  10. [backcolor=transparent]    [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onMessage[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]CPushMessage[backcolor=transparent] cPushMessage[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  11. [backcolor=transparent]            [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]e[backcolor=transparent]([backcolor=transparent]"MyMessageReceiver"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"onMessage, messageId: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] cPushMessage[backcolor=transparent].[backcolor=transparent]getMessageId[backcolor=transparent]()[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] cPushMessage[backcolor=transparent].[backcolor=transparent]getTitle[backcolor=transparent]()[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", content:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] cPushMessage[backcolor=transparent].[backcolor=transparent]getContent[backcolor=transparent]());
  12. [backcolor=transparent]    [backcolor=transparent]}
  13. [backcolor=transparent]    [backcolor=transparent]@Override
  14. [backcolor=transparent]    [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onNotificationOpened[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]String[backcolor=transparent] extraMap[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  15. [backcolor=transparent]        [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]e[backcolor=transparent]([backcolor=transparent]"MyMessageReceiver"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"onNotificationOpened, title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] title [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", summary: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] summary [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", extraMap:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] extraMap[backcolor=transparent]);
  16. [backcolor=transparent]    [backcolor=transparent]}
  17. [backcolor=transparent]    [backcolor=transparent]@Override
  18. [backcolor=transparent]    [backcolor=transparent]protected[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onNotificationClickedWithNoAction[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]String[backcolor=transparent] extraMap[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  19. [backcolor=transparent]        [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]e[backcolor=transparent]([backcolor=transparent]"MyMessageReceiver"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"onNotificationClickedWithNoAction, title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] title [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", summary: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] summary [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", extraMap:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] extraMap[backcolor=transparent]);
  20. [backcolor=transparent]    [backcolor=transparent]}
  21. [backcolor=transparent]    [backcolor=transparent]@Override
  22. [backcolor=transparent]    [backcolor=transparent]protected[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onNotificationReceivedInApp[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]int[backcolor=transparent] openType[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] openActivity[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] openUrl[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  23. [backcolor=transparent]        [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]e[backcolor=transparent]([backcolor=transparent]"MyMessageReceiver"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"onNotificationReceivedInApp, title: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] title [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", summary: "[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]", openType:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] openType [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", openActivity:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] openActivity [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]", openUrl:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] openUrl[backcolor=transparent]);
  24. [backcolor=transparent]    [backcolor=transparent]}
  25. [backcolor=transparent]    [backcolor=transparent]@Override
  26. [backcolor=transparent]    [backcolor=transparent]protected[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] onNotificationRemoved[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] messageId[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  27. [backcolor=transparent]        [backcolor=transparent]Log[backcolor=transparent].[backcolor=transparent]e[backcolor=transparent]([backcolor=transparent]"MyMessageReceiver"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"onNotificationRemoved"[backcolor=transparent]);
  28. [backcolor=transparent]    [backcolor=transparent]}
  29. [backcolor=transparent]}

将该receiver添加到AndroidManifest.xml中
  1. [backcolor=transparent]<!-- 消息接收 (用户可自主扩展) -->
  2. [backcolor=transparent]<receiver
  3. [backcolor=transparent]    [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]".MyMessageReceiver"
  4. [backcolor=transparent]    [backcolor=transparent]android:exported[backcolor=transparent]=[backcolor=transparent]"false"[backcolor=transparent]>[backcolor=transparent] [backcolor=transparent]<!-- 为保证receiver安全,建议设置不可导出,如需对其他应用开放可通过android:permission进行限制 -->
  5. [backcolor=transparent]    [backcolor=transparent]<intent-filter>
  6. [backcolor=transparent]        [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.push2.action.NOTIFICATION_OPENED"[backcolor=transparent] [backcolor=transparent]/>
  7. [backcolor=transparent]    [backcolor=transparent]</intent-filter>
  8. [backcolor=transparent]    [backcolor=transparent]<intent-filter>
  9. [backcolor=transparent]        [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.push2.action.NOTIFICATION_REMOVED"[backcolor=transparent] [backcolor=transparent]/>
  10. [backcolor=transparent]    [backcolor=transparent]</intent-filter>
  11. [backcolor=transparent]    [backcolor=transparent]<intent-filter>
  12. [backcolor=transparent]        [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.sdk.android.push.RECEIVE"[backcolor=transparent] [backcolor=transparent]/>
  13. [backcolor=transparent]    [backcolor=transparent]</intent-filter>
  14. [backcolor=transparent]</receiver>
[font=PingFangSC, "]如果是从V2.3.7及以下版本升级到V3.0.0及以上版本的用户,需将<action android:name="org.agoo.android.intent.action.RECEIVE" />改为<action android:name="com.alibaba.sdk.android.push.RECEIVE" />,否则会接收不到推送。 [font=PingFangSC, "]

3.5. Proguard配置

  1. [backcolor=transparent]-[backcolor=transparent]keepclasseswithmembernames [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]**[backcolor=transparent] [backcolor=transparent]{
  2. [backcolor=transparent]    [backcolor=transparent]native[backcolor=transparent] [backcolor=transparent]<methods>[backcolor=transparent];
  3. [backcolor=transparent]}
  4. [backcolor=transparent]-[backcolor=transparent]keepattributes [backcolor=transparent]Signature
  5. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] sun[backcolor=transparent].[backcolor=transparent]misc[backcolor=transparent].[backcolor=transparent]Unsafe[backcolor=transparent] [backcolor=transparent]{[backcolor=transparent] [backcolor=transparent]*;[backcolor=transparent] [backcolor=transparent]}
  6. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]taobao[backcolor=transparent].**[backcolor=transparent] [backcolor=transparent]{*;}
  7. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].**[backcolor=transparent] [backcolor=transparent]{*;}
  8. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]alipay[backcolor=transparent].**[backcolor=transparent] [backcolor=transparent]{*;}
  9. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]ut[backcolor=transparent].**[backcolor=transparent] [backcolor=transparent]{*;}
  10. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]ta[backcolor=transparent].**[backcolor=transparent] [backcolor=transparent]{*;}
  11. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] anet[backcolor=transparent].**{*;}
  12. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] anetwork[backcolor=transparent].**{*;}
  13. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] org[backcolor=transparent].[backcolor=transparent]android[backcolor=transparent].[backcolor=transparent]spdy[backcolor=transparent].**{*;}
  14. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] org[backcolor=transparent].[backcolor=transparent]android[backcolor=transparent].[backcolor=transparent]agoo[backcolor=transparent].**{*;}
  15. [backcolor=transparent]-[backcolor=transparent]keep [backcolor=transparent]class[backcolor=transparent] android[backcolor=transparent].[backcolor=transparent]os[backcolor=transparent].**{*;}
  16. [backcolor=transparent]-[backcolor=transparent]dontwarn com[backcolor=transparent].[backcolor=transparent]taobao[backcolor=transparent].**
  17. [backcolor=transparent]-[backcolor=transparent]dontwarn com[backcolor=transparent].[backcolor=transparent]alibaba[backcolor=transparent].**
  18. [backcolor=transparent]-[backcolor=transparent]dontwarn com[backcolor=transparent].[backcolor=transparent]alipay[backcolor=transparent].**
  19. [backcolor=transparent]-[backcolor=transparent]dontwarn anet[backcolor=transparent].**
  20. [backcolor=transparent]-[backcolor=transparent]dontwarn org[backcolor=transparent].[backcolor=transparent]android[backcolor=transparent].[backcolor=transparent]spdy[backcolor=transparent].**
  21. [backcolor=transparent]-[backcolor=transparent]dontwarn org[backcolor=transparent].[backcolor=transparent]android[backcolor=transparent].[backcolor=transparent]agoo[backcolor=transparent].**
  22. [backcolor=transparent]-[backcolor=transparent]dontwarn anetwork[backcolor=transparent].**
  23. [backcolor=transparent]-[backcolor=transparent]dontwarn com[backcolor=transparent].[backcolor=transparent]ut[backcolor=transparent].**
  24. [backcolor=transparent]-[backcolor=transparent]dontwarn com[backcolor=transparent].[backcolor=transparent]ta[backcolor=transparent].**
取消 提交回答
全部回答(0)
相关问答

1

回答

android 三个配置放在一起代表什么意思 - 安卓报错

2020-06-02 20:41:24 371浏览量 回答数 1

1

回答

android 三个配置放在一起代表什么意思-安卓报错

2020-05-31 15:05:16 318浏览量 回答数 1

1

回答

Intellij IDEA安装安卓sdk报错,No java sdk?报错

2020-06-08 19:18:10 858浏览量 回答数 1

1

回答

安卓端oss的sdk

2018-03-22 10:10:13 639浏览量 回答数 1

1

回答

安卓sdk 签名私有资源的指定有效时长的访问URL

2018-02-22 07:22:37 822浏览量 回答数 1

1

回答

使用安卓SDK下载OSS对象时出现超时

2018-02-10 03:18:20 1201浏览量 回答数 1

0

回答

【视频云端SDK】关于安卓指令集的兼容,Library xxx.so not found

2018-01-18 11:51:46 3459浏览量 回答数 0

1

回答

阿里云安卓推流sdk设置横屏

2017-03-25 14:54:41 2812浏览量 回答数 1

1

回答

安卓设备使用阿里云移动推送SDK的流程和原理是什么

2017-03-14 16:57:58 3511浏览量 回答数 1

1

回答

在安卓中必须搭建maven环境才可以用视频播放的sdk吗

2016-08-15 14:46:22 2027浏览量 回答数 1
+关注
文章
问答
问答排行榜
最热
最新
相关电子书
更多
Android热修复技术原理详解与升级探索
立即下载
《深入探索Android热修复技术原理》
立即下载
Android插件化:从入门到放弃
立即下载