├── .gitignore ├── LICENSE.txt ├── README.md ├── aar ├── common-1.0.10.aar ├── gslb-3.0.9.aar ├── push-internal-3.1.160901.aar └── usage-stats-2.5.1.aar ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── jiang │ │ └── android │ │ └── pushdemo │ │ ├── App.java │ │ ├── LauncherActivity.java │ │ ├── MainActivity.java │ │ └── PushService.java │ └── res │ ├── layout │ ├── activity_launcher.xml │ ├── activity_main.xml │ └── item.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── code.zip ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── push ├── .gitignore ├── build.gradle ├── libs │ ├── HwPush_SDK_V2705.jar │ ├── MiPush_SDK_Client_3_1_2.jar │ ├── com.coloros.mcssdk.jar │ └── pushsdk_v2.3.4.jar ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── jiang │ │ └── android │ │ └── push │ │ ├── Const.java │ │ ├── IPushManager.java │ │ ├── Message.java │ │ ├── Push.java │ │ ├── PushInterface.java │ │ ├── emui │ │ ├── EMHuaweiPushReceiver.java │ │ └── EMPushManager.java │ │ ├── flyme │ │ ├── FlymePushManager.java │ │ └── FlymeReceiver.java │ │ ├── jpush │ │ ├── JPushManager.java │ │ └── JPushReceiver.java │ │ ├── miui │ │ ├── MiuiPushManager.java │ │ └── MiuiReceiver.java │ │ ├── model │ │ └── TokenModel.java │ │ ├── oppo │ │ └── OppoPushManager.java │ │ ├── utils │ │ ├── BuildProperties.java │ │ ├── JHandler.java │ │ ├── JsonUtils.java │ │ ├── L.java │ │ ├── RomUtil.java │ │ └── Target.java │ │ └── vivo │ │ ├── PushMessageReceiverImpl.java │ │ └── ViVOPushManager.java │ └── res │ ├── drawable-hdpi │ ├── ic_launcher.png │ ├── pushnotify.png │ ├── send.png │ ├── start.png │ └── upload.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ ├── hwpush_ab_bottom_emui.9.png │ ├── hwpush_background_emui.9.png │ ├── hwpush_btn_check_off_emui.png │ ├── hwpush_btn_check_off_pressed_emui.png │ ├── hwpush_btn_check_on_emui.png │ ├── hwpush_btn_check_on_pressed_emui.png │ ├── hwpush_ic_cancel.png │ ├── hwpush_ic_cancel_light.png │ ├── hwpush_ic_toolbar_advance.png │ ├── hwpush_ic_toolbar_back.png │ ├── hwpush_ic_toolbar_collect.png │ ├── hwpush_ic_toolbar_delete.png │ ├── hwpush_ic_toolbar_multiple.png │ ├── hwpush_ic_toolbar_multiple1.png │ ├── hwpush_ic_toolbar_refresh.png │ ├── hwpush_list_activated_emui.9.png │ ├── hwpush_list_icon.png │ ├── hwpush_main_icon.png │ ├── hwpush_no_collection.png │ ├── hwpush_pic_ab_number.9.png │ ├── hwpush_pic_ab_number_light.9.png │ └── hwpush_progress.9.png │ ├── layout │ ├── hwpush_buttons_layout.xml │ ├── hwpush_collect_tip_dialog.xml │ ├── hwpush_collection_item.xml │ ├── hwpush_collection_listview.xml │ ├── hwpush_icons_layout.xml │ ├── hwpush_layout2.xml │ ├── hwpush_layout4.xml │ ├── hwpush_layout7.xml │ ├── hwpush_layout8.xml │ └── hwpush_msg_show.xml │ ├── values-zh-rCN │ └── hwpush_strings.xml │ └── values │ ├── hwpush_colors.xml │ ├── hwpush_strings.xml │ ├── hwpush_styles.xml │ ├── jpush_style.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | gradlew 11 | gradlew.bat 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # [DEPRECATED] 各大三方推送基本都已支持集成相关厂商的推送,请查阅相关三方推送文档 4 | 5 | 更方便的将各个rom厂商自己的推送服务进行集成,并统一管理,使用前还是需要熟悉各个平台的相关文档 6 | 7 | ### 请检查各个推送平台官网SDK版本,及时更新最新版 8 | 9 | 10 | ### 为什么不做成一个库 11 | 12 | 作为底层码农,每天忙于coding,可能没有太多的时间及时更新各个平台的sdk,所以这里只是写了一些思想性的东西,大家可以在此基础上根据需求自己优化功能.另外, 13 | 推送这种东西,各家app的做法都不相同,通过自己动手集成能了解各个平台推送特点,方便以后遇到问题自己可以解决,而且各个厂商的SDK更新不同,自己修改起来更方便。 14 | 15 | ### 各个平台的说明 16 | >1. MIUI系统将使用[小米推送](http://dev.xiaomi.com/doc/?page_id=1670) 17 | >2. Flyme系统将使用[魅族推送](https://open.flyme.cn/open-web/views/push.html?t=1476262864945) 18 | >3. EMUI系统将使用[华为推送](http://developer.huawei.com/push) 19 | >4. OPPO系统将使用[OPPO推送](https://push.oppo.com) 20 | >5. VIVO系统将使用[VIVO推送](https://dev.vivo.com.cn) 21 | >6. 其他系统将使用[JPush推送](https://www.jiguang.cn) 22 | 23 | 24 | ### 集成 25 | >1. 将如下4个SDK集成到项目中 26 | >* 华为SDK 请自行去[官网](http://developer.huawei.com/push)下载(推荐)或者[点击这里](https://raw.githubusercontent.com/jiang111/AndroidPush/master/push/libs/HwPush_SDK_V2705.jar) 并添加依赖 27 | >* 小米SDK 请自行去[官网](http://dev.xiaomi.com/doc/?page_id=1670)下载(推荐)或者[点击这里](https://raw.githubusercontent.com/jiang111/AndroidPush/master/push/libs/MiPush_SDK_Client_3_1_2.jar) 并添加依赖 28 | >* 魅族SDK 在app模块下依赖:implementation 'com.meizu.flyme.internet:push-internal-publish:3.3.+@aar' 29 | >* JPushSDK 在app模块下依赖:implementation 'cn.jiguang:jpush:2.1.8' 30 | >* vivoSDK 请自行去官网下载 31 | >* oppoSDK 请自行去官网下载 32 | >* 注意资源文件的配置,目前只有华为的需要,请去官网查看最新版是否需要这些资源 [华为推送官网](http://developer.huawei.com/push) [点我查看资源配置](https://github.com/jiang111/AndroidPush/tree/master/push/src/main) 33 | 34 | >2. 在app模块下新建包,包名为push(也可以叫其他名字),然后把如下代码全部拷贝进push包里 [点我查看代码](https://raw.githubusercontent.com/jiang111/AndroidPush/master/code.zip) 35 | 源码在[这里](https://github.com/jiang111/AndroidPush/tree/master/push/src/main/java/com/jiang/android/push) 36 | 37 | >3. 配置APP下的Manifest.xml文件 [注意:如出现推送不成功请仔细检查manifest里对该平台集成是否正确!!!] 38 | ``` 39 | //权限通用配置 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | //小米的权限 60 | 61 | 62 | 63 | 64 | //华为的权限 65 | //魅族的权限 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | //极光的配置 75 | 76 | 79 | 80 | 81 | 82 | //下面的配置需要复制到 application 节点下面 83 | //小米 84 | 88 | 94 | 95 | 99 | 101 | 102 | 105 | 106 | 107 | 108 | 109 | 110 | 114 | 115 | 116 | 117 | 118 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | //魅族 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | //华为 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | //极光 164 | 165 | 166 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 235 | 236 | 237 | 238 | 239 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 271 | 276 | 277 | 280 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | ``` 297 | 298 | 299 | >4. 在app下的gradle文件加上如下这几句话 300 | ``` 301 | //app下的gradle 302 | android { 303 | ... 304 | defaultConfig { 305 | ndk { 306 | abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a' 307 | } 308 | //如果有多渠道,请将下面的代码同样放一份到多渠道里面 309 | manifestPlaceholders = [ 310 | JPUSH_APPKEY : "替换成自己的appkey", 311 | JPUSH_CHANNEL : " 替换成自己的channel", 312 | PNAME : applicationId 313 | ] 314 | } 315 | } 316 | ``` 317 | 至此,集成已经全部搞定。 318 | 319 | ### 使用 320 | 321 | 322 | * 在Application的onCreate()中初始化: 323 | 324 | ``` 325 | @Override 326 | public void onCreate() { 327 | super.onCreate(); 328 | //设置小米和魅族的推送id和key 329 |        Const.setMiUI_APP("APP_MIUI_ID", "APP_MIUI_KEY"); 330 | Const.setFlyme_APP("APP_FLYME_ID", "APP_FLYME_KEY"); 331 | Const.setColor_APP("key", "secret"); 332 | //初始化推送 333 |        Push.register(this, BuildConfig.ISDEBUG, new PushInterfaceImpl(this)); 334 | } 335 | ``` 336 | 337 | * 新建PushInterfaceImpl类,或者任意名字,实现 PushInterface接口,此后收到的推送信息都会在该类的相关方法中回调,注意线程。并且看一下PushInterface类的注释 338 | 339 | ``` 340 | public class PushInterfaceImpl implements PushInterface { 341 | ... 342 | } 343 | 344 | ``` 345 | 目前为止,推送已经集成了,可以去各平台测试。 346 | 347 | 348 | * -------------------------分步介绍----------------------------- 349 | 350 | 351 | * 在使用推送之前,请在gradle中配置JPUSH_APPKEY字段为jpush平台的key,华为不需要配置key,他会在注册的时候自动生成key,在小米和魅族开放平台申请的id和key进行配置,小米和魅族的配置方法: 352 | ``` 353 | Const.setMiUI_APP("APP_MIUI_ID", "APP_MIUI_KEY"); 354 | Const.setFlyme_APP("APP_FLYME_ID", "APP_FLYME_KEY"); 355 | ``` 356 | 357 | * 注册推送服务,这里会根据自己的rom型号自动配置相关的推送服务: 358 | ``` 359 | Push.register(this, BuildConfig.DEBUG); //BuildConfig.DEBUG代表是否开启各个推送服务的debug功能. 360 | ``` 361 | 362 | * 创建PushInterface接口的子类,并在相关的方法里实现自己的业务逻辑,并在Push类中进行配置。 363 | ``` 364 | Push.setPushInterface(pushInterface); 365 | ``` 366 | 367 | * 获取当前rom平台: 368 | ``` 369 | RomUtil.rom(); 370 | ``` 371 | 372 | * 其他操作 373 | ``` 374 | Push.unregister(getApplicationContext()); //取消注册 375 | Push.resume(getApplicationContext()); //开启推送 376 | Push.pause(getApplicationContext()); //暂停推送 377 | Push.setAlias(getApplicationContext(), "ALIAS"); //设置别名 378 | ``` 379 | 380 | ### 混淆 381 | 请参考 https://github.com/jiang111/AndroidPush/blob/master/push/proguard-rules.pro 382 | 383 | 384 | ### 注意项 385 | 1. 不要直接将库引用到自己的项目,而是要将代码拷贝到项目里,如果推送不成功,请仔细查看官网的说明文档 386 | 2. 仔细阅读各个平台的推送文档,尤其是魅族和华为的。 387 | 388 | 389 | ### 各个推送平台的特点 390 | 1. 小米和极光推送做的都差不多,通知栏和透传消息都可以自己控制,没什么可说的. 391 | 2. flyme推送 392 | 无法对通知栏做任何的控制(除了改改样式),一切都由后台控制 393 | 透传消息的话,在Receiver的onMessage()的回调中使用. 394 | 395 | 3. 华为推送 396 | 如果推送的消息类型为透传消息的话,则无法使用extra字段,只可以用onPushMsg()回调中的 byte[] msg 参数. 397 | 通知栏的话,由于点击动作和魅族一样,都是由后台控制. 398 | 399 | ### 常见rom的区分 400 | 参考自: http://www.jianshu.com/p/6e6828755667 401 | 402 | ### 其他不错的库 403 | >* android开发不得不收集的小知识点 https://github.com/jiang111/awesome-android-tips 404 | >* 仿iOS下载按钮 https://github.com/jiang111/CProgressButton 405 | >* 可指定任意位置的指向性对话框 https://github.com/jiang111/IndicatorDialog 406 | >* 通过RecyclerView实现的联系人 https://github.com/jiang111/IndexRecyclerView 407 | >* 学习RxJava操作符的APP https://github.com/jiang111/RxJavaApp 408 | 409 | ### 捐赠 410 | 如果您觉得本项目对您有帮助,欢迎请作者一杯咖啡

411 | ![](https://raw.githubusercontent.com/jiang111/RxJavaApp/master/qrcode/wechat_alipay.png) 412 | 413 | 414 | ### License 415 | 416 | Copyright 2016 NewTab 417 | 418 | Licensed under the Apache License, Version 2.0 (the "License"); 419 | you may not use this file except in compliance with the License. 420 | You may obtain a copy of the License at 421 | 422 | http://www.apache.org/licenses/LICENSE-2.0 423 | 424 | Unless required by applicable law or agreed to in writing, software 425 | distributed under the License is distributed on an "AS IS" BASIS, 426 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 427 | See the License for the specific language governing permissions and 428 | limitations under the License. 429 | -------------------------------------------------------------------------------- /aar/common-1.0.10.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/aar/common-1.0.10.aar -------------------------------------------------------------------------------- /aar/gslb-3.0.9.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/aar/gslb-3.0.9.aar -------------------------------------------------------------------------------- /aar/push-internal-3.1.160901.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/aar/push-internal-3.1.160901.aar -------------------------------------------------------------------------------- /aar/usage-stats-2.5.1.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/aar/usage-stats-2.5.1.aar -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.jiang.android.pushdemo" 7 | minSdkVersion 18 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | ndk { 12 | abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a','x86' 13 | 14 | } 15 | manifestPlaceholders = [ 16 | JPUSH_PKGNAME : applicationId, 17 | JPUSH_APPKEY : "3df7e06ec9bf5e79abdc4a6a", 18 | JPUSH_CHANNEL : "develop", 19 | PNAME : applicationId 20 | ] 21 | 22 | 23 | } 24 | buildTypes { 25 | release { 26 | 27 | //混淆 28 | minifyEnabled true 29 | //优化zipAlign 30 | zipAlignEnabled true 31 | //移除无用的resource 32 | shrinkResources true 33 | 34 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 35 | } 36 | } 37 | 38 | 39 | } 40 | 41 | dependencies { 42 | implementation fileTree(include: ['*.jar'], dir: 'libs') 43 | implementation 'com.android.support:appcompat-v7:28.0.0' 44 | implementation 'com.github.jiang111:RvAdapter:1.0' 45 | implementation project(':push') 46 | } 47 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/jiang/androidsdk/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 58 | 59 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 137 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /app/src/main/java/com/jiang/android/pushdemo/App.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.pushdemo; 2 | 3 | import android.app.Application; 4 | 5 | import com.jiang.android.push.Const; 6 | 7 | /** 8 | * Created by jiang on 2016/10/8. 9 | */ 10 | 11 | public class App extends Application { 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | Const.setMiUI_APP("2882303761517516835", "5911751629835"); 17 | Const.setFlyme_APP("110029", "9efb4973a717495bbae156ee5b66978b"); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/jiang/android/pushdemo/LauncherActivity.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.pushdemo; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | 8 | public class LauncherActivity extends AppCompatActivity { 9 | 10 | private static final String TAG = "LauncherActivity"; 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_launcher); 16 | 17 | String scheml = getIntent().getScheme(); 18 | if (scheml.equals("custom")) { 19 | Uri uri = getIntent().getData(); 20 | Log.i(TAG, "onCreate: " + uri.getQueryParameter("aaa")); 21 | } else { 22 | String aa = getIntent().getExtras().getString("aaa"); 23 | Log.i(TAG, "onCreate: " + aa); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/jiang/android/pushdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.pushdemo; 2 | 3 | import android.content.ClipboardManager; 4 | import android.content.Context; 5 | import android.content.pm.PackageManager; 6 | import android.os.Bundle; 7 | import android.support.v4.app.ActivityCompat; 8 | import android.support.v4.content.ContextCompat; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.AppCompatButton; 11 | import android.support.v7.widget.LinearLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.view.View; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.jiang.android.push.*; 18 | import com.jiang.android.push.BuildConfig; 19 | import com.jiang.android.push.utils.RomUtil; 20 | import com.jiang.android.rvadapter.BaseAdapter; 21 | import com.jiang.android.rvadapter.BaseViewHolder; 22 | import com.jiang.android.rvadapter.OnItemClickListener; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 28 | 29 | private AppCompatButton register; 30 | private AppCompatButton unregister; 31 | private AppCompatButton open; 32 | private AppCompatButton close; 33 | private RecyclerView recyclerView; 34 | 35 | List mDatas = new ArrayList<>(); 36 | PushInterface pushInterface = new PushInterface() { 37 | @Override 38 | public void onRegister(Context context, String registerID) { 39 | addData("onRegister id:" + registerID+"; target: "+ RomUtil.rom().toString()); 40 | } 41 | 42 | @Override 43 | public void onUnRegister(Context context) { 44 | addData("onUnRegister"); 45 | } 46 | 47 | @Override 48 | public void onPaused(Context context) { 49 | addData("onPaused"); 50 | } 51 | 52 | @Override 53 | public void onResume(Context context) { 54 | addData("onResume"); 55 | } 56 | 57 | @Override 58 | public void onMessage(Context context, Message message) { 59 | 60 | addData(message.toString()); 61 | } 62 | 63 | @Override 64 | public void onMessageClicked(Context context, Message message) { 65 | 66 | addData("MessageClicked: " + message.toString()); 67 | } 68 | 69 | @Override 70 | public void onCustomMessage(Context context, Message message) { 71 | 72 | addData(message.toString()); 73 | } 74 | 75 | @Override 76 | public void onAlias(Context context, String alias) { 77 | addData("alias: " + alias); 78 | } 79 | }; 80 | private AppCompatButton alias; 81 | 82 | @Override 83 | protected void onCreate(Bundle savedInstanceState) { 84 | super.onCreate(savedInstanceState); 85 | setContentView(R.layout.activity_main); 86 | if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { 87 | ActivityCompat.requestPermissions(this, 88 | new String[]{android.Manifest.permission.READ_PHONE_STATE}, 89 | 100); 90 | } 91 | 92 | //android.permission.WRITE_SETTINGS 93 | if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_SETTINGS) != PackageManager.PERMISSION_GRANTED) { 94 | ActivityCompat.requestPermissions(this, 95 | new String[]{android.Manifest.permission.WRITE_SETTINGS}, 96 | 1300); 97 | } 98 | register = (AppCompatButton) findViewById(R.id.register); 99 | register.setOnClickListener(this); 100 | unregister = (AppCompatButton) findViewById(R.id.unregister); 101 | unregister.setOnClickListener(this); 102 | open = (AppCompatButton) findViewById(R.id.open); 103 | open.setOnClickListener(this); 104 | close = (AppCompatButton) findViewById(R.id.close); 105 | alias = (AppCompatButton) findViewById(R.id.alias); 106 | close.setOnClickListener(this); 107 | alias.setOnClickListener(this); 108 | recyclerView = (RecyclerView) findViewById(R.id.rv); 109 | 110 | Push.setPushInterface(pushInterface); 111 | 112 | mDatas.add("--------- log ----------"); 113 | recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 114 | BaseAdapter adapter = new BaseAdapter() { 115 | @Override 116 | protected void onBindView(BaseViewHolder baseViewHolder, int i) { 117 | 118 | TextView title = baseViewHolder.getView(R.id.tv); 119 | title.setText(mDatas.get(i)); 120 | } 121 | 122 | @Override 123 | protected int getLayoutID(int i) { 124 | return R.layout.item; 125 | } 126 | 127 | @Override 128 | public int getItemCount() { 129 | return mDatas.size(); 130 | } 131 | }; 132 | 133 | adapter.setOnItemClickListener(new OnItemClickListener() { 134 | @Override 135 | public void onItemClick(int i) { 136 | ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 137 | cm.setText(mDatas.get(i)); 138 | Toast.makeText(MainActivity.this, "复制成功", Toast.LENGTH_SHORT).show(); 139 | } 140 | }); 141 | recyclerView.setAdapter(adapter); 142 | 143 | } 144 | 145 | @Override 146 | public void onClick(View view) { 147 | switch (view.getId()) { 148 | case R.id.register: 149 | register(); 150 | toast("开始注册"); 151 | break; 152 | case R.id.unregister: 153 | Push.unregister(this); 154 | toast("取消注册"); 155 | break; 156 | case R.id.open: 157 | Push.resume(this); 158 | toast("开启推送"); 159 | break; 160 | case R.id.close: 161 | Push.pause(this); 162 | toast("开始暂停"); 163 | break; 164 | case R.id.alias: 165 | Push.setAlias(this, "haha"); 166 | toast("alias"); 167 | break; 168 | } 169 | 170 | } 171 | 172 | private void toast(String s) { 173 | Toast.makeText(this, s, Toast.LENGTH_SHORT).show(); 174 | } 175 | 176 | private void register() { 177 | Push.register(this, BuildConfig.DEBUG); 178 | 179 | } 180 | 181 | private void addData(String value) { 182 | mDatas.add(value); 183 | recyclerView.getAdapter().notifyDataSetChanged(); 184 | 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /app/src/main/java/com/jiang/android/pushdemo/PushService.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.pushdemo; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import com.jiang.android.push.Message; 7 | import com.jiang.android.push.PushInterface; 8 | 9 | /** 10 | * Created by jiang on 2016/10/9. 11 | */ 12 | 13 | public class PushService implements PushInterface { 14 | 15 | private static final String TAG = "PushServiceforMyOwn"; 16 | 17 | @Override 18 | public void onRegister(Context context, String registerID) { 19 | Log.i(TAG, "onRegister: " + " id: " + registerID); 20 | 21 | } 22 | 23 | @Override 24 | public void onUnRegister(Context context) { 25 | Log.i(TAG, "onUnRegister: "); 26 | 27 | } 28 | 29 | @Override 30 | public void onPaused(Context context) { 31 | Log.i(TAG, "onPaused: "); 32 | 33 | } 34 | 35 | @Override 36 | public void onResume(Context context) { 37 | Log.i(TAG, "onResume: "); 38 | 39 | } 40 | 41 | @Override 42 | public void onMessage(Context context, Message message) { 43 | Log.i(TAG, "onMessage: " + message.toString()); 44 | 45 | } 46 | 47 | @Override 48 | public void onMessageClicked(Context context, Message message) { 49 | Log.i(TAG, "onMessageClicked: " + message.toString()); 50 | 51 | } 52 | 53 | @Override 54 | public void onCustomMessage(Context context, Message message) { 55 | Log.i(TAG, "onCustomMessage: " + message.toString()); 56 | 57 | } 58 | 59 | @Override 60 | public void onAlias(Context context, String alias) { 61 | Log.i(TAG, "onAlias: " + alias); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 22 | 23 | 30 | 31 | 38 | 45 | 52 | 53 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidPush 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.1.0' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | maven { url "https://jitpack.io" } 21 | google() 22 | 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/code.zip -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | android.useDeprecatedNdk=true。 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 26 18:23:11 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /push/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /push/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group = 'com.github.jiang111' 4 | android { 5 | compileSdkVersion 28 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 5 11 | versionName "1.1.2" 12 | ndk { 13 | abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a' 14 | 15 | } 16 | manifestPlaceholders = [ 17 | JPUSH_PKGNAME: "library", 18 | JPUSH_APPKEY : "library", 19 | JPUSH_CHANNEL: "developer", 20 | PNAME : "library" 21 | ] 22 | 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | /** 29 | * flyme 30 | */ 31 | implementation 'com.android.support:support-v4:28.0.0' 32 | implementation 'com.android.volley:volley:1.1.0' 33 | implementation 'com.squareup.okhttp:okhttp:2.1.0' 34 | implementation 'com.meizu.flyme.internet:push-internal-publish:3.3.+@aar' 35 | /** 36 | * jpush 37 | */ 38 | implementation fileTree(include: ['*.jar'], dir: 'libs') 39 | implementation 'cn.jiguang:jpush:2.1.8' 40 | implementation files('libs/pushsdk_v2.3.4.jar') 41 | implementation files('libs/com.coloros.mcssdk.jar') 42 | } 43 | -------------------------------------------------------------------------------- /push/libs/HwPush_SDK_V2705.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/libs/HwPush_SDK_V2705.jar -------------------------------------------------------------------------------- /push/libs/MiPush_SDK_Client_3_1_2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/libs/MiPush_SDK_Client_3_1_2.jar -------------------------------------------------------------------------------- /push/libs/com.coloros.mcssdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/libs/com.coloros.mcssdk.jar -------------------------------------------------------------------------------- /push/libs/pushsdk_v2.3.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/libs/pushsdk_v2.3.4.jar -------------------------------------------------------------------------------- /push/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/jiang/androidsdk/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep public class * extends android.content.BroadcastReceiver 20 | -keep class com.xiaomi.mipush.sdk.DemoMessageReceiver {*;} 21 | #可以防止一个误报的 warning 导致无法成功编译,如果编译使用的 Android 版本是 23。 22 | -dontwarn com.xiaomi.push.** 23 | # library 24 | -keep class com.jiang.android.push.**{*;} 25 | 26 | 27 | # huawei 28 | -keep class com.huawei.**{*;} 29 | -keep class com.hianalytics.android.**{*;} 30 | -keep class com.baidu.mapapi.**{*;} 31 | -dontwarn com.huawei.** 32 | 33 | # jpush 34 | -dontoptimize 35 | -dontpreverify 36 | 37 | -dontwarn cn.jpush.** 38 | -keep class cn.jpush.** { *; } 39 | #==================gson && protobuf========================== 40 | -dontwarn com.google.** 41 | -keep class com.google.gson.** {*;} 42 | -keep class com.google.protobuf.** {*;} 43 | -------------------------------------------------------------------------------- /push/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | 40 | 41 | 42 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 118 | 119 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 134 | 137 | 138 | 139 | /> 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 154 | 155 | 156 | 157 | 158 | 161 | 162 | 163 | 164 | 167 | 168 | 169 | 170 | 171 | 172 | 176 | 182 | 183 | 187 | 190 | 191 | 194 | 195 | 196 | 197 | 198 | 199 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 214 | 219 | 220 | 223 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/Const.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push; 2 | 3 | import android.text.TextUtils; 4 | 5 | /** 6 | * Created by jiang on 2016/10/8. 7 | */ 8 | 9 | public class Const { 10 | 11 | private static String miui_app_id = null; 12 | private static String miui_app_key = null; 13 | private static String flyme_app_id = null; 14 | private static String flyme_app_key = null; 15 | private static String color_app_key = null; 16 | private static String color_app_secret = null; 17 | 18 | public static String getMiui_app_id() { 19 | if (TextUtils.isEmpty(miui_app_id)) { 20 | throw new NullPointerException("please config miui_app_id before use it"); 21 | } 22 | return miui_app_id; 23 | } 24 | 25 | public static String getMiui_app_key() { 26 | if (TextUtils.isEmpty(miui_app_key)) { 27 | throw new NullPointerException("please config miui_app_key before use it"); 28 | } 29 | return miui_app_key; 30 | } 31 | 32 | public static String getFlyme_app_id() { 33 | if (TextUtils.isEmpty(flyme_app_id)) { 34 | throw new NullPointerException("please config flyme_app_id before use it"); 35 | } 36 | return flyme_app_id; 37 | } 38 | 39 | public static String getFlyme_app_key() { 40 | if (TextUtils.isEmpty(flyme_app_key)) { 41 | throw new NullPointerException("please config flyme_app_key before use it"); 42 | } 43 | return flyme_app_key; 44 | } 45 | 46 | 47 | public static void setMiUI_APP(String miui_app_id, String miui_app_key) { 48 | setMiui_app_id(miui_app_id); 49 | setMiui_app_key(miui_app_key); 50 | } 51 | 52 | public static void setFlyme_APP(String flyme_app_id, String flyme_app_key) { 53 | setFlyme_app_id(flyme_app_id); 54 | setFlyme_app_key(flyme_app_key); 55 | } 56 | 57 | public static void setColor_APP(String app_key, String app_secret) { 58 | Const.color_app_key = app_key; 59 | Const.color_app_secret = app_secret; 60 | } 61 | 62 | public static String getColor_app_key() { 63 | if (TextUtils.isEmpty(color_app_key)) { 64 | throw new NullPointerException("please config color_app_key before use it"); 65 | } 66 | return color_app_key; 67 | } 68 | 69 | public static String getColor_app_secret() { 70 | if (TextUtils.isEmpty(color_app_secret)) { 71 | throw new NullPointerException("please config color_app_secret before use it"); 72 | } 73 | return color_app_secret; 74 | } 75 | 76 | private static void setMiui_app_id(String miui_app_id) { 77 | Const.miui_app_id = miui_app_id; 78 | } 79 | 80 | private static void setMiui_app_key(String miui_app_key) { 81 | Const.miui_app_key = miui_app_key; 82 | } 83 | 84 | private static void setFlyme_app_id(String flyme_app_id) { 85 | Const.flyme_app_id = flyme_app_id; 86 | } 87 | 88 | private static void setFlyme_app_key(String flyme_app_key) { 89 | Const.flyme_app_key = flyme_app_key; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/IPushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push; 2 | 3 | import android.content.Context; 4 | 5 | import com.jiang.android.push.model.TokenModel; 6 | 7 | public interface IPushManager { 8 | void register(Context context, boolean debug, final PushInterface pushInterface); 9 | 10 | void unregister(Context context); 11 | 12 | void setPushInterface(PushInterface pushInterface); 13 | 14 | void setAlias(final Context context, String alias); 15 | 16 | TokenModel getToken(Context context); 17 | 18 | void pause(Context context); 19 | 20 | void resume(Context context); 21 | } -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/Message.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push; 2 | 3 | import com.jiang.android.push.utils.Target; 4 | 5 | /** 6 | * 将消息整合成Message model 7 | * Created by jiang on 2016/10/8. 8 | */ 9 | 10 | public final class Message { 11 | private int notifyID; //这个字段用于通知的消息类型,在透传中都是默认0 12 | private String messageID; 13 | private String title; 14 | private String message; 15 | private String extra; 16 | private Target target; 17 | 18 | public int getNotifyID() { 19 | return notifyID; 20 | } 21 | 22 | public void setNotifyID(int notifyID) { 23 | this.notifyID = notifyID; 24 | } 25 | 26 | public String getMessageID() { 27 | return messageID; 28 | } 29 | 30 | public void setMessageID(String messageID) { 31 | this.messageID = messageID; 32 | } 33 | 34 | public Target getTarget() { 35 | return target; 36 | } 37 | 38 | public void setTarget(Target target) { 39 | this.target = target; 40 | } 41 | 42 | public String getTitle() { 43 | return title; 44 | } 45 | 46 | public void setTitle(String title) { 47 | this.title = title; 48 | } 49 | 50 | public String getMessage() { 51 | return message; 52 | } 53 | 54 | public void setMessage(String message) { 55 | this.message = message; 56 | } 57 | 58 | public String getExtra() { 59 | return extra; 60 | } 61 | 62 | public void setExtra(String extra) { 63 | this.extra = extra; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "Message{" + 69 | "notifyID=" + notifyID + 70 | ", messageID='" + messageID + '\'' + 71 | ", title='" + title + '\'' + 72 | ", message='" + message + '\'' + 73 | ", extra='" + extra + '\'' + 74 | ", target=" + target + 75 | '}'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/Push.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push; 2 | 3 | import android.content.Context; 4 | import android.text.TextUtils; 5 | 6 | import com.jiang.android.push.emui.EMPushManager; 7 | import com.jiang.android.push.jpush.JPushManager; 8 | import com.jiang.android.push.miui.MiuiPushManager; 9 | import com.jiang.android.push.model.TokenModel; 10 | import com.jiang.android.push.oppo.OppoPushManager; 11 | import com.jiang.android.push.utils.RomUtil; 12 | import com.jiang.android.push.utils.Target; 13 | import com.jiang.android.push.vivo.ViVOPushManager; 14 | 15 | /** 16 | * Created by jiang on 2016/10/8. 17 | */ 18 | 19 | public class Push { 20 | 21 | 22 | private static IPushManager pushManager; 23 | 24 | 25 | public static void initPushManager(IPushManager pushManager) { 26 | Push.pushManager = pushManager; 27 | } 28 | 29 | /** 30 | * 初始化配置 31 | * 32 | * @param context 33 | * @param debug 34 | */ 35 | public static void register(Context context, boolean debug) { 36 | register(context, debug, null); 37 | } 38 | 39 | /** 40 | * 注册 41 | * 42 | * @param context 43 | * @param debug 44 | * @param pushInterface 45 | */ 46 | public static void register(Context context, boolean debug, final PushInterface pushInterface) { 47 | if (context == null) return; 48 | init(); 49 | pushManager.register(context, debug, pushInterface); 50 | 51 | 52 | } 53 | 54 | private static void init() { 55 | 56 | if (pushManager != null) return; 57 | 58 | if (RomUtil.rom() == Target.EMUI) { 59 | pushManager = new EMPushManager(); 60 | } 61 | if (RomUtil.rom() == Target.MIUI) { 62 | pushManager = new MiuiPushManager(); 63 | } 64 | 65 | if (RomUtil.rom() == Target.JPUSH) { 66 | pushManager = new JPushManager(); 67 | } 68 | 69 | if (RomUtil.rom() == Target.VIVO) { 70 | pushManager = new ViVOPushManager(); 71 | 72 | } 73 | if (RomUtil.rom() == Target.OPPO) { 74 | pushManager = new OppoPushManager(); 75 | } 76 | 77 | 78 | } 79 | 80 | 81 | public static void unregister(Context context) { 82 | if (context == null) return; 83 | pushManager.unregister(context); 84 | } 85 | 86 | 87 | /** 88 | * @param pushInterface 89 | */ 90 | public static void setPushInterface(PushInterface pushInterface) { 91 | if (pushInterface == null) return; 92 | pushManager.setPushInterface(pushInterface); 93 | } 94 | 95 | 96 | /** 97 | * 设置别名, 98 | * 华为不支持alias的写法,所以只能用tag,tag只能放map,所以alias作为value,key为name 99 | * 100 | * @param context 101 | * @param alias 102 | */ 103 | public static void setAlias(final Context context, String alias) { 104 | if (context == null) return; 105 | if (TextUtils.isEmpty(alias)) return; 106 | pushManager.setAlias(context, alias); 107 | } 108 | 109 | /** 110 | * 获取唯一的token 111 | * 112 | * @param context 113 | * @return 114 | */ 115 | public static TokenModel getToken(Context context) { 116 | if (context == null) return null; 117 | return pushManager.getToken(context); 118 | } 119 | 120 | 121 | /** 122 | * 停止推送 123 | */ 124 | public static void pause(Context context) { 125 | if (context == null) return; 126 | pushManager.pause(context); 127 | } 128 | 129 | 130 | /** 131 | * 开始推送 132 | */ 133 | public static void resume(Context context) { 134 | if (context == null) return; 135 | pushManager.resume(context); 136 | 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/PushInterface.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * warning: 7 | * 在flyme的推送中,不会回调onMessage()和onMessageClicked()方法 8 | * 在华为推送中,不会回调onMessage(),onMessageClicked()和onAlias()方法 9 | * 如上两个方法不会回调是因为设计的时候,通知栏的点击事件由后台负责控制,手机端值负责处理透传消息 10 | *

11 | * oppo中不需要自己处理,所以用不到PushInterface 12 | *

13 | * Created by jiang on 2016/10/8. 14 | */ 15 | 16 | public interface PushInterface { 17 | 18 | /** 19 | * 注册成功之后回调 20 | * 21 | * @param context 22 | * @param registerID 23 | */ 24 | void onRegister(Context context, String registerID); 25 | 26 | /** 27 | * 取消注册成功 28 | * 29 | * @param context 30 | */ 31 | void onUnRegister(Context context); 32 | 33 | /** 34 | * 暂停推送 35 | * 36 | * @param context 37 | */ 38 | void onPaused(Context context); 39 | 40 | /** 41 | * 开启推送 42 | * 43 | * @param context 44 | */ 45 | void onResume(Context context); 46 | 47 | /** 48 | * 通知下来之后 49 | * 50 | * @param context 51 | * @param message 52 | */ 53 | void onMessage(Context context, Message message); 54 | 55 | /** 56 | * 通知栏被点击之后 57 | * 58 | * @param context 59 | * @param message 60 | */ 61 | void onMessageClicked(Context context, Message message); 62 | 63 | /** 64 | * 透传消息 65 | * 66 | * @param context 67 | * @param message 68 | */ 69 | void onCustomMessage(Context context, Message message); 70 | 71 | 72 | /** 73 | * 别名设置成功的回调 74 | * 75 | * @param context 76 | * @param alias 77 | */ 78 | void onAlias(Context context, String alias); 79 | } 80 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/emui/EMHuaweiPushReceiver.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.emui; 2 | 3 | import android.app.NotificationManager; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | 7 | import com.huawei.android.pushagent.PushReceiver; 8 | import com.jiang.android.push.Message; 9 | import com.jiang.android.push.PushInterface; 10 | import com.jiang.android.push.utils.JHandler; 11 | import com.jiang.android.push.utils.L; 12 | import com.jiang.android.push.utils.Target; 13 | 14 | /** 15 | * Created by jiang on 2016/10/8. 16 | */ 17 | 18 | public class EMHuaweiPushReceiver extends PushReceiver { 19 | 20 | private static String mToken = null; 21 | 22 | 23 | private static PushInterface mPushInterface; 24 | 25 | public static void registerInterface(PushInterface pushInterface) { 26 | mPushInterface = pushInterface; 27 | } 28 | 29 | public static PushInterface getPushInterface() { 30 | return mPushInterface; 31 | } 32 | 33 | public static String getmToken() { 34 | return mToken; 35 | } 36 | 37 | 38 | @Override 39 | public void onToken(final Context context, final String token, Bundle extras) { 40 | String belongId = extras.getString("belongId"); 41 | String content = "获取token和belongId成功,token = " + token + ",belongId = " + belongId; 42 | L.i(content); 43 | mToken = token; 44 | if (mPushInterface != null) { 45 | JHandler.handler().post(new Runnable() { 46 | @Override 47 | public void run() { 48 | mPushInterface.onRegister(context, token); 49 | } 50 | }); 51 | } 52 | } 53 | 54 | @Override 55 | public void onPushMsg(Context context, byte[] bytes, String s) { 56 | super.onPushMsg(context, bytes, s); 57 | L.i("onPushMsg..."); 58 | } 59 | 60 | 61 | @Override 62 | public boolean onPushMsg(final Context context, byte[] msg, Bundle bundle) { 63 | //这里是透传消息, msg是透传消息的字节数组 bundle字段没用 64 | L.i("onPushMsg: " + new String(msg)); 65 | try { 66 | String content = new String(msg, "UTF-8"); 67 | if (mPushInterface != null) { 68 | final Message message = new Message(); 69 | message.setMessage(content); 70 | //华为的sdk在透传的时候无法实现extra字段,这里要注意 71 | message.setExtra("{}"); 72 | message.setTarget(Target.EMUI); 73 | JHandler.handler().post(new Runnable() { 74 | @Override 75 | public void run() { 76 | mPushInterface.onCustomMessage(context, message); 77 | } 78 | }); 79 | } 80 | L.i(content); 81 | } catch (Exception e) { 82 | e.printStackTrace(); 83 | } 84 | return false; 85 | } 86 | 87 | 88 | /** 89 | * 在华为的sdk中,通知栏的事件只有三种: 90 | *

91 | * NOTIFICATION_OPENED, //通知栏中的通知被点击打开 92 | * NOTIFICATION_CLICK_BTN, //通知栏中通知上的按钮被点击 93 | * PLUGINRSP, //标签上报回应 94 | * 95 | * @param context 96 | * @param event 97 | * @param extras 98 | */ 99 | public void onEvent(final Context context, Event event, Bundle extras) { 100 | L.i("onEvent: "); 101 | if (Event.NOTIFICATION_OPENED.equals(event) || Event.NOTIFICATION_CLICK_BTN.equals(event)) { 102 | int notifyId = extras.getInt(BOUND_KEY.pushNotifyId, 0); 103 | if (0 != notifyId) { 104 | NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 105 | manager.cancel(notifyId); 106 | } 107 | String content = "收到通知附加消息: " + extras.getString(BOUND_KEY.pushMsgKey); 108 | L.i(content); 109 | // try { 110 | // if (mPushInterface != null) { 111 | // final Message message = new Message(); 112 | // message.setTitle("暂无"); 113 | // message.setNotifyID(notifyId); 114 | // message.setMessage(content); 115 | // message.setExtra(JsonUtils.getJson(extras)); 116 | // message.setTarget(Target.EMUI); 117 | // JHandler.handler().post(new Runnable() { 118 | // @Override 119 | // public void run() { 120 | // mPushInterface.onMessageClicked(context, message); 121 | // } 122 | // }); 123 | // } 124 | // } catch (Exception e) { 125 | // e.printStackTrace(); 126 | // } 127 | } else if (Event.PLUGINRSP.equals(event)) { 128 | final int TYPE_LBS = 1; 129 | final int TYPE_TAG = 2; 130 | int reportType = extras.getInt(BOUND_KEY.PLUGINREPORTTYPE, -1); 131 | boolean isSuccess = extras.getBoolean(BOUND_KEY.PLUGINREPORTRESULT, false); 132 | String message = ""; 133 | if (TYPE_LBS == reportType) { 134 | message = "LBS report result :"; 135 | } else if (TYPE_TAG == reportType) { 136 | message = "TAG report result :"; 137 | } 138 | L.i(message + isSuccess); 139 | // showPushMessage(PustDemoActivity.RECEIVE_TAG_LBS_MSG, message + isSuccess); 140 | super.onEvent(context, event, extras); 141 | } 142 | } 143 | 144 | 145 | public static void clearPushInterface() { 146 | mPushInterface = null; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/emui/EMPushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.emui; 2 | 3 | import android.content.Context; 4 | 5 | import com.huawei.android.pushagent.api.PushManager; 6 | import com.jiang.android.push.IPushManager; 7 | import com.jiang.android.push.PushInterface; 8 | import com.jiang.android.push.model.TokenModel; 9 | import com.jiang.android.push.utils.RomUtil; 10 | import com.jiang.android.push.utils.Target; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | public class EMPushManager implements IPushManager { 16 | @Override 17 | public void register(Context context, boolean debug, PushInterface pushInterface) { 18 | if (pushInterface != null) { 19 | EMHuaweiPushReceiver.registerInterface(pushInterface); 20 | } 21 | PushManager.requestToken(context); 22 | 23 | } 24 | 25 | @Override 26 | public void unregister(Context context) { 27 | EMHuaweiPushReceiver.clearPushInterface(); 28 | PushManager.deregisterToken(context, getToken(context).getToken()); 29 | 30 | } 31 | 32 | @Override 33 | public void setPushInterface(PushInterface pushInterface) { 34 | if (pushInterface != null) { 35 | EMHuaweiPushReceiver.registerInterface(pushInterface); 36 | } 37 | } 38 | 39 | @Override 40 | public void setAlias(Context context, String alias) { 41 | Map tag = new HashMap<>(); 42 | tag.put("name", alias); 43 | PushManager.setTags(context, tag); 44 | } 45 | 46 | @Override 47 | public TokenModel getToken(Context context) { 48 | if (context == null) 49 | return null; 50 | TokenModel result = new TokenModel(); 51 | result.setTarget(RomUtil.rom()); 52 | result.setToken(EMHuaweiPushReceiver.getmToken()); 53 | return result; 54 | } 55 | 56 | @Override 57 | public void pause(Context context) { 58 | PushManager.enableReceiveNormalMsg(context, false); 59 | PushManager.enableReceiveNotifyMsg(context, false); 60 | if (EMHuaweiPushReceiver.getPushInterface() != null) { 61 | EMHuaweiPushReceiver.getPushInterface().onPaused(context); 62 | } 63 | 64 | } 65 | 66 | @Override 67 | public void resume(Context context) { 68 | PushManager.enableReceiveNormalMsg(context, true); 69 | PushManager.enableReceiveNotifyMsg(context, true); 70 | if (EMHuaweiPushReceiver.getPushInterface() != null) { 71 | EMHuaweiPushReceiver.getPushInterface().onResume(context); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/flyme/FlymePushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.flyme; 2 | 3 | import android.content.Context; 4 | 5 | import com.jiang.android.push.Const; 6 | import com.jiang.android.push.IPushManager; 7 | import com.jiang.android.push.PushInterface; 8 | import com.jiang.android.push.model.TokenModel; 9 | import com.jiang.android.push.utils.RomUtil; 10 | import com.meizu.cloud.pushsdk.PushManager; 11 | 12 | public class FlymePushManager implements IPushManager { 13 | @Override 14 | public void register(Context context, boolean debug, PushInterface pushInterface) { 15 | if (pushInterface != null) { 16 | FlymeReceiver.registerInterface(pushInterface); 17 | } 18 | PushManager.register(context, Const.getFlyme_app_id(), Const.getFlyme_app_key()); 19 | } 20 | 21 | @Override 22 | public void unregister(Context context) { 23 | FlymeReceiver.clearPushInterface(); 24 | PushManager.unRegister(context, Const.getFlyme_app_id(), Const.getFlyme_app_key()); 25 | } 26 | 27 | @Override 28 | public void setPushInterface(PushInterface pushInterface) { 29 | if (pushInterface != null) { 30 | FlymeReceiver.registerInterface(pushInterface); 31 | } 32 | } 33 | 34 | @Override 35 | public void setAlias(Context context, String alias) { 36 | PushManager.subScribeAlias(context, Const.getFlyme_app_id(), Const.getFlyme_app_key(), getToken(context).getToken(), alias); 37 | 38 | } 39 | 40 | @Override 41 | public TokenModel getToken(Context context) { 42 | if (context == null) 43 | return null; 44 | TokenModel result = new TokenModel(); 45 | result.setTarget(RomUtil.rom()); 46 | result.setToken(PushManager.getPushId(context)); 47 | return result; 48 | } 49 | 50 | @Override 51 | public void pause(Context context) { 52 | PushManager.unRegister(context, Const.getFlyme_app_id(), Const.getFlyme_app_key()); 53 | if (FlymeReceiver.getPushInterface() != null) { 54 | FlymeReceiver.getPushInterface().onPaused(context); 55 | } 56 | } 57 | 58 | @Override 59 | public void resume(Context context) { 60 | PushManager.register(context, Const.getMiui_app_id(), Const.getFlyme_app_key()); 61 | if (FlymeReceiver.getPushInterface() != null) { 62 | FlymeReceiver.getPushInterface().onResume(context); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/flyme/FlymeReceiver.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.flyme; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | 6 | import com.jiang.android.push.Message; 7 | import com.jiang.android.push.PushInterface; 8 | import com.jiang.android.push.utils.JHandler; 9 | import com.jiang.android.push.utils.L; 10 | import com.jiang.android.push.utils.Target; 11 | import com.meizu.cloud.pushsdk.MzPushMessageReceiver; 12 | import com.meizu.cloud.pushsdk.notification.PushNotificationBuilder; 13 | import com.meizu.cloud.pushsdk.platform.message.PushSwitchStatus; 14 | import com.meizu.cloud.pushsdk.platform.message.RegisterStatus; 15 | import com.meizu.cloud.pushsdk.platform.message.SubAliasStatus; 16 | import com.meizu.cloud.pushsdk.platform.message.SubTagsStatus; 17 | import com.meizu.cloud.pushsdk.platform.message.UnRegisterStatus; 18 | 19 | /** 20 | * flyme push 21 | * 如果发现onregister回调了两次,那就得删除相关的代码,主要是因为flyme的sdk分老版本和新版本 22 | * Created by jiang on 2016/10/8. 23 | */ 24 | 25 | public class FlymeReceiver extends MzPushMessageReceiver { 26 | 27 | private static PushInterface mPushInterface = null; 28 | 29 | public static void registerInterface(PushInterface pushInterface) { 30 | 31 | mPushInterface = pushInterface; 32 | } 33 | 34 | 35 | public static PushInterface getPushInterface() { 36 | return mPushInterface; 37 | } 38 | 39 | @Override 40 | public void onRegister(final Context context, final String pushid) { 41 | //应用在接受返回的pushid 42 | L.i("onRegister called pushId: " + pushid); 43 | if (mPushInterface != null) { 44 | JHandler.handler().post(new Runnable() { 45 | @Override 46 | public void run() { 47 | mPushInterface.onRegister(context, pushid); 48 | 49 | } 50 | }); 51 | } 52 | } 53 | 54 | /** 55 | * 若该回调有数据,就证明是透传消息,否则全部都是通知消息 56 | * 57 | * @param context 58 | * @param s 59 | */ 60 | @Override 61 | public void onMessage(final Context context, final String s) { 62 | L.i("onMessage called: s:" + s); 63 | if (mPushInterface != null) { 64 | final Message message = new Message(); 65 | message.setMessageID(""); 66 | message.setTarget(Target.FLYME); 67 | message.setExtra(s); 68 | JHandler.handler().post(new Runnable() { 69 | @Override 70 | public void run() { 71 | 72 | 73 | mPushInterface.onCustomMessage(context, message); 74 | 75 | 76 | } 77 | }); 78 | } 79 | } 80 | 81 | @Override 82 | public void onMessage(Context context, Intent intent) { 83 | super.onMessage(context, intent); 84 | } 85 | 86 | @Override 87 | public void onUnRegister(final Context context, boolean b) { 88 | //调用PushManager.unRegister(context)方法后,会在此回调反注册状态 89 | L.i("onUnRegister called"); 90 | if (b == true) { 91 | if (mPushInterface != null) { 92 | JHandler.handler().post(new Runnable() { 93 | @Override 94 | public void run() { 95 | mPushInterface.onUnRegister(context); 96 | 97 | } 98 | }); 99 | } 100 | } 101 | } 102 | 103 | //设置通知栏小图标 104 | @Override 105 | public void onUpdateNotificationBuilder(PushNotificationBuilder pushNotificationBuilder) { 106 | // pushNotificationBuilder.setmStatusbarIcon(R.drawable.mz_stat_share_weibo); 107 | } 108 | 109 | @Override 110 | public void onPushStatus(Context context, PushSwitchStatus pushSwitchStatus) { 111 | //检查通知栏和透传消息开关状态回调 112 | } 113 | 114 | @Override 115 | public void onRegisterStatus(final Context context, final RegisterStatus registerStatus) { 116 | //新版订阅回调 117 | if (mPushInterface != null) { 118 | JHandler.handler().post(new Runnable() { 119 | @Override 120 | public void run() { 121 | mPushInterface.onRegister(context, registerStatus.getPushId()); 122 | } 123 | }); 124 | } 125 | } 126 | 127 | @Override 128 | public void onUnRegisterStatus(final Context context, UnRegisterStatus unRegisterStatus) { 129 | //新版反订阅回调 130 | L.i("onUnRegisterStatus"); 131 | if (mPushInterface != null) { 132 | JHandler.handler().post(new Runnable() { 133 | @Override 134 | public void run() { 135 | mPushInterface.onUnRegister(context); 136 | } 137 | }); 138 | } 139 | } 140 | 141 | @Override 142 | public void onSubTagsStatus(Context context, SubTagsStatus subTagsStatus) { 143 | //标签回调 144 | L.i("onSubTagsStatus"); 145 | } 146 | 147 | @Override 148 | public void onSubAliasStatus(final Context context, final SubAliasStatus subAliasStatus) { 149 | L.i("onSubAliasStatus"); 150 | if (mPushInterface != null) { 151 | JHandler.handler().post(new Runnable() { 152 | @Override 153 | public void run() { 154 | mPushInterface.onAlias(context, subAliasStatus.getAlias()); 155 | } 156 | }); 157 | } 158 | 159 | //别名回调 160 | } 161 | 162 | public static void clearPushInterface() { 163 | mPushInterface = null; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/jpush/JPushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.jpush; 2 | 3 | import android.content.Context; 4 | 5 | import com.jiang.android.push.IPushManager; 6 | import com.jiang.android.push.PushInterface; 7 | import com.jiang.android.push.model.TokenModel; 8 | import com.jiang.android.push.utils.L; 9 | import com.jiang.android.push.utils.RomUtil; 10 | 11 | import java.util.Set; 12 | 13 | import cn.jpush.android.api.JPushInterface; 14 | import cn.jpush.android.api.TagAliasCallback; 15 | 16 | public class JPushManager implements IPushManager { 17 | @Override 18 | public void register(Context context, boolean debug, PushInterface pushInterface) { 19 | if (pushInterface != null) { 20 | JPushReceiver.registerInterface(pushInterface); 21 | } 22 | JPushInterface.init(context); 23 | JPushInterface.setDebugMode(debug); 24 | } 25 | 26 | @Override 27 | public void unregister(Context context) { 28 | JPushReceiver.clearPushInterface(); 29 | JPushInterface.stopPush(context); 30 | } 31 | 32 | @Override 33 | public void setPushInterface(PushInterface pushInterface) { 34 | if (pushInterface != null) { 35 | JPushReceiver.registerInterface(pushInterface); 36 | } 37 | } 38 | 39 | @Override 40 | public void setAlias(final Context context, String alias) { 41 | JPushInterface.setAlias(context, alias, new TagAliasCallback() { 42 | @Override 43 | public void gotResult(int i, String s, Set set) { 44 | if (i == 0) { // 这里极光规定0代表成功 45 | if (JPushReceiver.getPushInterface() != null) { 46 | L.i("JPushInterface.setAlias"); 47 | JPushReceiver.getPushInterface().onAlias(context, s); 48 | 49 | } 50 | } 51 | } 52 | }); 53 | } 54 | 55 | @Override 56 | public TokenModel getToken(Context context) { 57 | if (context == null) 58 | return null; 59 | TokenModel result = new TokenModel(); 60 | result.setTarget(RomUtil.rom()); 61 | result.setToken(JPushInterface.getRegistrationID(context)); 62 | return result; 63 | } 64 | 65 | @Override 66 | public void pause(Context context) { 67 | if (!JPushInterface.isPushStopped(context)) { 68 | JPushInterface.stopPush(context); 69 | if (JPushReceiver.getPushInterface() != null) { 70 | JPushReceiver.getPushInterface().onPaused(context); 71 | } 72 | } 73 | } 74 | 75 | @Override 76 | public void resume(Context context) { 77 | if (JPushInterface.isPushStopped(context)) { 78 | JPushInterface.resumePush(context); 79 | if (JPushReceiver.getPushInterface() != null) { 80 | JPushReceiver.getPushInterface().onResume(context); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/jpush/JPushReceiver.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.jpush; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | 8 | import com.jiang.android.push.Message; 9 | import com.jiang.android.push.PushInterface; 10 | import com.jiang.android.push.utils.L; 11 | import com.jiang.android.push.utils.Target; 12 | 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.util.Iterator; 17 | 18 | import cn.jpush.android.api.JPushInterface; 19 | 20 | /** 21 | * Created by jiang on 2016/10/8. 22 | */ 23 | 24 | public class JPushReceiver extends BroadcastReceiver { 25 | 26 | 27 | private static PushInterface mPushInterface; 28 | 29 | public static void registerInterface(PushInterface pushInterface) { 30 | mPushInterface = pushInterface; 31 | } 32 | 33 | public static PushInterface getPushInterface() { 34 | return mPushInterface; 35 | } 36 | 37 | @Override 38 | public void onReceive(Context context, Intent intent) { 39 | Bundle bundle = intent.getExtras(); 40 | L.i("[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle)); 41 | int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); 42 | String messageId = bundle.getString(JPushInterface.EXTRA_MSG_ID); 43 | String extraMessage = bundle.getString(JPushInterface.EXTRA_EXTRA); 44 | 45 | if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { 46 | String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); 47 | L.i("[MyReceiver] 接收Registration Id : " + regId); 48 | if (mPushInterface != null) 49 | mPushInterface.onRegister(context, regId); 50 | 51 | } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { 52 | L.i("[MyReceiver] 接收到推送下来的自定义消息: " + extraMessage); 53 | if (mPushInterface != null) { 54 | Message message = new Message(); 55 | message.setTitle(bundle.getString(JPushInterface.EXTRA_TITLE)); 56 | message.setMessageID(messageId); 57 | message.setMessage(bundle.getString(JPushInterface.EXTRA_MESSAGE)); 58 | message.setExtra(extraMessage); 59 | message.setTarget(Target.JPUSH); 60 | mPushInterface.onCustomMessage(context, message); 61 | } 62 | 63 | } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { 64 | 65 | L.i("[MyReceiver] 接收到推送下来的通知"); 66 | 67 | L.i("[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId); 68 | if (mPushInterface != null) { 69 | Message message = new Message(); 70 | message.setNotifyID(notifactionId); 71 | message.setMessageID(messageId); 72 | message.setTitle(bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE)); 73 | message.setMessage(bundle.getString(JPushInterface.EXTRA_ALERT)); 74 | message.setExtra(extraMessage); 75 | message.setTarget(Target.JPUSH); 76 | mPushInterface.onMessage(context, message); 77 | } 78 | 79 | } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { 80 | L.i("[MyReceiver] 用户点击打开了通知"); 81 | if (mPushInterface != null) { 82 | Message message = new Message(); 83 | message.setNotifyID(notifactionId); 84 | message.setMessageID(messageId); 85 | message.setTitle(bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE)); 86 | message.setMessage(bundle.getString(JPushInterface.EXTRA_ALERT)); 87 | message.setExtra(extraMessage); 88 | message.setTarget(Target.JPUSH); 89 | mPushInterface.onMessageClicked(context, message); 90 | } 91 | 92 | 93 | } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { 94 | L.i("[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); 95 | //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. 96 | 97 | } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { 98 | boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); 99 | L.i("[MyReceiver]" + intent.getAction() + " connected state change to " + connected); 100 | } else { 101 | L.i("[MyReceiver] Unhandled intent - " + intent.getAction()); 102 | } 103 | } 104 | 105 | // 打印所有的 intent extra 数据 106 | private static String printBundle(Bundle bundle) { 107 | StringBuilder sb = new StringBuilder(); 108 | for (String key : bundle.keySet()) { 109 | if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { 110 | sb.append("\nkey:").append(key).append(", value:").append(bundle.getInt(key)); 111 | } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) { 112 | sb.append("\nkey:").append(key).append(", value:").append(bundle.getBoolean(key)); 113 | } else if (key.equals(JPushInterface.EXTRA_EXTRA)) { 114 | if (bundle.getString(JPushInterface.EXTRA_EXTRA).isEmpty()) { 115 | L.i("This message has no Extra data"); 116 | continue; 117 | } 118 | 119 | try { 120 | JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); 121 | Iterator it = json.keys(); 122 | 123 | while (it.hasNext()) { 124 | String myKey = it.next().toString(); 125 | sb.append("\nkey:").append(key + ", value: [" + 126 | myKey).append(" - ").append(json.optString(myKey) + "]"); 127 | } 128 | } catch (JSONException e) { 129 | L.i("Get message extra JSON error!"); 130 | } 131 | 132 | } else { 133 | sb.append("\nkey:").append(key).append(", value:" + bundle.getString(key)); 134 | } 135 | } 136 | return sb.toString(); 137 | } 138 | 139 | public static void clearPushInterface() { 140 | mPushInterface = null; 141 | } 142 | 143 | 144 | } 145 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/miui/MiuiPushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.miui; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Context; 5 | import android.os.Process; 6 | 7 | import com.jiang.android.push.Const; 8 | import com.jiang.android.push.IPushManager; 9 | import com.jiang.android.push.PushInterface; 10 | import com.jiang.android.push.model.TokenModel; 11 | import com.jiang.android.push.utils.L; 12 | import com.jiang.android.push.utils.RomUtil; 13 | import com.xiaomi.channel.commonutils.logger.LoggerInterface; 14 | import com.xiaomi.mipush.sdk.Logger; 15 | import com.xiaomi.mipush.sdk.MiPushClient; 16 | 17 | import java.util.List; 18 | 19 | public class MiuiPushManager implements IPushManager { 20 | @Override 21 | public void register(Context context, boolean debug, PushInterface pushInterface) { 22 | if (pushInterface != null) { 23 | MiuiReceiver.registerInterface(pushInterface); 24 | } 25 | if (shouldInit(context)) { 26 | MiPushClient.registerPush(context, Const.getMiui_app_id(), Const.getMiui_app_key()); 27 | } 28 | if (debug) { 29 | LoggerInterface newLogger = new LoggerInterface() { 30 | @Override 31 | public void setTag(String tag) { 32 | // ignore 33 | } 34 | 35 | @Override 36 | public void log(String content, Throwable t) { 37 | L.i("content" + content + " exception: " + t.toString()); 38 | } 39 | 40 | @Override 41 | public void log(String content) { 42 | L.i("miui: " + content); 43 | } 44 | }; 45 | Logger.setLogger(context, newLogger); 46 | } 47 | } 48 | 49 | 50 | private static boolean shouldInit(Context context) { 51 | ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)); 52 | List processInfos = am.getRunningAppProcesses(); 53 | String mainProcessName = context.getPackageName(); 54 | int myPid = Process.myPid(); 55 | for (ActivityManager.RunningAppProcessInfo info : processInfos) { 56 | if (info.pid == myPid && mainProcessName.equals(info.processName)) { 57 | return true; 58 | } 59 | } 60 | return false; 61 | } 62 | 63 | @Override 64 | public void unregister(Context context) { 65 | MiuiReceiver.clearPushInterface(); 66 | MiPushClient.unregisterPush(context); 67 | } 68 | 69 | @Override 70 | public void setPushInterface(PushInterface pushInterface) { 71 | if (pushInterface != null) { 72 | MiuiReceiver.registerInterface(pushInterface); 73 | } 74 | } 75 | 76 | @Override 77 | public void setAlias(Context context, String alias) { 78 | MiPushClient.setAlias(context, alias, null); 79 | 80 | } 81 | 82 | @Override 83 | public TokenModel getToken(Context context) { 84 | if (context == null) 85 | return null; 86 | TokenModel result = new TokenModel(); 87 | result.setTarget(RomUtil.rom()); 88 | result.setToken(MiPushClient.getRegId(context)); 89 | return result; 90 | } 91 | 92 | @Override 93 | public void pause(Context context) { 94 | MiPushClient.pausePush(context, null); 95 | if (MiuiReceiver.getPushInterface() != null) { 96 | MiuiReceiver.getPushInterface().onPaused(context); 97 | } 98 | } 99 | 100 | @Override 101 | public void resume(Context context) { 102 | MiPushClient.resumePush(context, null); 103 | if (MiuiReceiver.getPushInterface() != null) { 104 | MiuiReceiver.getPushInterface().onResume(context); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/miui/MiuiReceiver.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.miui; 2 | 3 | import android.content.Context; 4 | import android.text.TextUtils; 5 | import android.util.Log; 6 | 7 | import com.jiang.android.push.Message; 8 | import com.jiang.android.push.PushInterface; 9 | import com.jiang.android.push.utils.JHandler; 10 | import com.jiang.android.push.utils.JsonUtils; 11 | import com.jiang.android.push.utils.L; 12 | import com.jiang.android.push.utils.Target; 13 | import com.xiaomi.mipush.sdk.ErrorCode; 14 | import com.xiaomi.mipush.sdk.MiPushClient; 15 | import com.xiaomi.mipush.sdk.MiPushCommandMessage; 16 | import com.xiaomi.mipush.sdk.MiPushMessage; 17 | import com.xiaomi.mipush.sdk.PushMessageReceiver; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * 小米推送下来的消息运行在子线程 23 | * Created by jiang on 2016/10/8. 24 | */ 25 | 26 | public class MiuiReceiver extends PushMessageReceiver { 27 | 28 | private static final String TAG = "MiuiReceiver"; 29 | private String mRegId; 30 | private long mResultCode = -1; 31 | private String mReason; 32 | private String mCommand; 33 | private String mMessage; 34 | private String mTopic; 35 | private String mAlias; 36 | private String mUserAccount; 37 | private String mStartTime; 38 | private String mEndTime; 39 | 40 | 41 | private static PushInterface mPushInterface; 42 | 43 | /** 44 | * @param pushInterface 45 | */ 46 | public static void registerInterface(PushInterface pushInterface) { 47 | 48 | mPushInterface = pushInterface; 49 | } 50 | 51 | public static PushInterface getPushInterface() { 52 | return mPushInterface; 53 | } 54 | 55 | 56 | @Override 57 | public void onReceivePassThroughMessage(final Context context, MiPushMessage message) { 58 | mMessage = message.getContent(); 59 | if (!TextUtils.isEmpty(message.getTopic())) { 60 | mTopic = message.getTopic(); 61 | } else if (!TextUtils.isEmpty(message.getAlias())) { 62 | mAlias = message.getAlias(); 63 | } else if (!TextUtils.isEmpty(message.getUserAccount())) { 64 | mUserAccount = message.getUserAccount(); 65 | } 66 | if (mPushInterface != null) { 67 | final Message result = new Message(); 68 | result.setMessageID(message.getMessageId()); 69 | result.setTitle(message.getTitle()); 70 | result.setMessage(message.getContent()); 71 | result.setExtra(mMessage); 72 | result.setTarget(Target.MIUI); 73 | try { 74 | // result.setExtra(JsonUtils.setJson(message.getExtra()).toString()); 75 | result.setExtra(message.getContent()); 76 | } catch (Exception e) { 77 | L.i("onReceivePassThroughMessage: " + e.toString()); 78 | result.setExtra("{}"); 79 | } 80 | JHandler.handler().post(new Runnable() { 81 | @Override 82 | public void run() { 83 | mPushInterface.onCustomMessage(context, result); 84 | } 85 | }); 86 | } 87 | 88 | 89 | } 90 | 91 | @Override 92 | public void onNotificationMessageClicked(final Context context, MiPushMessage message) { 93 | mMessage = message.getContent(); 94 | if (!TextUtils.isEmpty(message.getTopic())) { 95 | mTopic = message.getTopic(); 96 | } else if (!TextUtils.isEmpty(message.getAlias())) { 97 | mAlias = message.getAlias(); 98 | } else if (!TextUtils.isEmpty(message.getUserAccount())) { 99 | mUserAccount = message.getUserAccount(); 100 | } 101 | if (mPushInterface != null) { 102 | final Message result = new Message(); 103 | result.setNotifyID(message.getNotifyId()); 104 | result.setMessageID(message.getMessageId()); 105 | result.setTitle(mTopic); 106 | result.setMessage(mMessage); 107 | result.setTarget(Target.MIUI); 108 | try { 109 | result.setExtra(JsonUtils.setJson(message.getExtra()).toString()); 110 | // result.setExtra(message.getContent()); 111 | } catch (Exception e) { 112 | Log.e(TAG, "onNotificationMessageClicked: " + e.toString()); 113 | result.setExtra("{}"); 114 | } 115 | JHandler.handler().post(new Runnable() { 116 | @Override 117 | public void run() { 118 | mPushInterface.onMessageClicked(context, result); 119 | } 120 | }); 121 | } 122 | } 123 | 124 | @Override 125 | public void onNotificationMessageArrived(final Context context, MiPushMessage message) { 126 | mMessage = message.getContent(); 127 | if (!TextUtils.isEmpty(message.getTopic())) { 128 | mTopic = message.getTopic(); 129 | } else if (!TextUtils.isEmpty(message.getAlias())) { 130 | mAlias = message.getAlias(); 131 | } else if (!TextUtils.isEmpty(message.getUserAccount())) { 132 | mUserAccount = message.getUserAccount(); 133 | } 134 | if (mPushInterface != null) { 135 | final Message result = new Message(); 136 | result.setTitle(message.getTitle()); 137 | result.setMessageID(message.getMessageId()); 138 | result.setNotifyID(message.getNotifyId()); 139 | result.setMessage(message.getDescription()); 140 | result.setTarget(Target.MIUI); 141 | try { 142 | result.setExtra(JsonUtils.setJson(message.getExtra()).toString()); 143 | // result.setExtra(message.getContent()); 144 | } catch (Exception e) { 145 | L.i("onReceivePassThroughMessage: " + e.toString()); 146 | result.setExtra("{}"); 147 | } 148 | JHandler.handler().post(new Runnable() { 149 | @Override 150 | public void run() { 151 | mPushInterface.onMessage(context, result); 152 | } 153 | }); 154 | } 155 | } 156 | 157 | @Override 158 | public void onCommandResult(final Context context, MiPushCommandMessage message) { 159 | String command = message.getCommand(); 160 | List arguments = message.getCommandArguments(); 161 | String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null); 162 | String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null); 163 | if (MiPushClient.COMMAND_REGISTER.equals(command)) { 164 | if (message.getResultCode() == ErrorCode.SUCCESS) { 165 | mRegId = cmdArg1; 166 | if (mPushInterface != null) { 167 | JHandler.handler().post(new Runnable() { 168 | @Override 169 | public void run() { 170 | mPushInterface.onRegister(context, mRegId); 171 | } 172 | }); 173 | } 174 | } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) { 175 | if (message.getResultCode() == ErrorCode.SUCCESS) { 176 | mAlias = cmdArg1; 177 | if (mPushInterface != null) { 178 | JHandler.handler().post(new Runnable() { 179 | @Override 180 | public void run() { 181 | mPushInterface.onAlias(context, mAlias); 182 | } 183 | }); 184 | } 185 | } 186 | } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) { 187 | if (message.getResultCode() == ErrorCode.SUCCESS) { 188 | mAlias = cmdArg1; 189 | } 190 | } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) { 191 | if (message.getResultCode() == ErrorCode.SUCCESS) { 192 | mTopic = cmdArg1; 193 | } 194 | } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) { 195 | if (message.getResultCode() == ErrorCode.SUCCESS) { 196 | mTopic = cmdArg1; 197 | } 198 | } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) { 199 | if (message.getResultCode() == ErrorCode.SUCCESS) { 200 | mStartTime = cmdArg1; 201 | mEndTime = cmdArg2; 202 | } 203 | } 204 | } 205 | 206 | 207 | } 208 | 209 | @Override 210 | public void onReceiveRegisterResult(Context context, MiPushCommandMessage miPushCommandMessage) { 211 | super.onReceiveRegisterResult(context, miPushCommandMessage); 212 | } 213 | 214 | public static void clearPushInterface() { 215 | mPushInterface = null; 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/model/TokenModel.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.model; 2 | 3 | import com.jiang.android.push.utils.Target; 4 | 5 | /** 6 | * Created by jiang on 2016/10/8. 7 | */ 8 | 9 | public class TokenModel { 10 | private String mToken; 11 | private Target mTarget; 12 | 13 | public String getToken() { 14 | return mToken; 15 | } 16 | 17 | public void setToken(String mToken) { 18 | this.mToken = mToken; 19 | } 20 | 21 | public Target getTarget() { 22 | return mTarget; 23 | } 24 | 25 | public void setTarget(Target mTarget) { 26 | this.mTarget = mTarget; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/oppo/OppoPushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.oppo; 2 | 3 | import android.content.Context; 4 | 5 | import com.coloros.mcssdk.PushManager; 6 | import com.coloros.mcssdk.callback.PushCallback; 7 | import com.coloros.mcssdk.mode.SubscribeResult; 8 | import com.jiang.android.push.Const; 9 | import com.jiang.android.push.IPushManager; 10 | import com.jiang.android.push.PushInterface; 11 | import com.jiang.android.push.model.TokenModel; 12 | import com.jiang.android.push.utils.RomUtil; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class OppoPushManager implements IPushManager { 18 | @Override 19 | public void register(Context context, boolean debug, PushInterface pushInterface) { 20 | PushManager.getInstance().register(context, Const.getColor_app_key(), Const.getColor_app_secret(), new PushCallback() { 21 | @Override 22 | public void onRegister(int i, String s) { 23 | 24 | 25 | } 26 | 27 | @Override 28 | public void onUnRegister(int i) { 29 | 30 | } 31 | 32 | @Override 33 | public void onGetAliases(int i, List list) { 34 | 35 | } 36 | 37 | @Override 38 | public void onSetAliases(int i, List list) { 39 | 40 | } 41 | 42 | @Override 43 | public void onUnsetAliases(int i, List list) { 44 | 45 | } 46 | 47 | @Override 48 | public void onSetUserAccounts(int i, List list) { 49 | 50 | } 51 | 52 | @Override 53 | public void onUnsetUserAccounts(int i, List list) { 54 | 55 | } 56 | 57 | @Override 58 | public void onGetUserAccounts(int i, List list) { 59 | 60 | } 61 | 62 | @Override 63 | public void onSetTags(int i, List list) { 64 | 65 | } 66 | 67 | @Override 68 | public void onUnsetTags(int i, List list) { 69 | 70 | } 71 | 72 | @Override 73 | public void onGetTags(int i, List list) { 74 | 75 | } 76 | 77 | @Override 78 | public void onGetPushStatus(int i, int i1) { 79 | 80 | } 81 | 82 | @Override 83 | public void onSetPushTime(int i, String s) { 84 | 85 | } 86 | 87 | @Override 88 | public void onGetNotificationStatus(int i, int i1) { 89 | 90 | } 91 | }); 92 | } 93 | 94 | @Override 95 | public void unregister(Context context) { 96 | PushManager.getInstance().unRegister(); 97 | 98 | } 99 | 100 | @Override 101 | public void setPushInterface(PushInterface pushInterface) { 102 | 103 | } 104 | 105 | @Override 106 | public void setAlias(Context context, String alias) { 107 | 108 | List list = new ArrayList<>(); 109 | list.add(alias); 110 | PushManager.getInstance().setAliases(list); 111 | } 112 | 113 | @Override 114 | public TokenModel getToken(Context context) { 115 | if (context == null) 116 | return null; 117 | TokenModel result = new TokenModel(); 118 | result.setTarget(RomUtil.rom()); 119 | result.setToken(PushManager.getInstance().getRegisterID()); 120 | return result; 121 | } 122 | 123 | @Override 124 | public void pause(Context context) { 125 | PushManager.getInstance().pausePush(); 126 | 127 | } 128 | 129 | @Override 130 | public void resume(Context context) { 131 | PushManager.getInstance().resumePush(); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/utils/BuildProperties.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.utils; 2 | 3 | import android.os.Environment; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.util.Collection; 9 | import java.util.Enumeration; 10 | import java.util.Map.Entry; 11 | import java.util.Properties; 12 | import java.util.Set; 13 | 14 | /** 15 | * Created by jiang on 2016/10/8. 16 | */ 17 | 18 | public class BuildProperties { 19 | 20 | private final Properties properties; 21 | 22 | private BuildProperties() throws IOException { 23 | properties = new Properties(); 24 | properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"))); 25 | } 26 | 27 | public boolean containsKey(final Object key) { 28 | return properties.containsKey(key); 29 | } 30 | 31 | public boolean containsValue(final Object value) { 32 | return properties.containsValue(value); 33 | } 34 | 35 | public Set> entrySet() { 36 | return properties.entrySet(); 37 | } 38 | 39 | public String getProperty(final String name) { 40 | return properties.getProperty(name); 41 | } 42 | 43 | public String getProperty(final String name, final String defaultValue) { 44 | return properties.getProperty(name, defaultValue); 45 | } 46 | 47 | public boolean isEmpty() { 48 | return properties.isEmpty(); 49 | } 50 | 51 | public Enumeration keys() { 52 | return properties.keys(); 53 | } 54 | 55 | public Set keySet() { 56 | return properties.keySet(); 57 | } 58 | 59 | public int size() { 60 | return properties.size(); 61 | } 62 | 63 | public Collection values() { 64 | return properties.values(); 65 | } 66 | 67 | public static BuildProperties newInstance() throws IOException { 68 | return new BuildProperties(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/utils/JHandler.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.utils; 2 | 3 | import android.os.Looper; 4 | 5 | /** 6 | * Created by jiang on 2016/10/10. 7 | */ 8 | 9 | public class JHandler { 10 | private static android.os.Handler mHandler = null; 11 | 12 | public static android.os.Handler handler() { 13 | if (mHandler == null) { 14 | synchronized (JHandler.class) { 15 | mHandler = new android.os.Handler(Looper.getMainLooper()); 16 | } 17 | } 18 | return mHandler; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/utils/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.utils; 2 | 3 | import android.os.Bundle; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | import java.lang.reflect.Array; 10 | import java.util.Collection; 11 | import java.util.Iterator; 12 | import java.util.List; 13 | import java.util.Map; 14 | import java.util.Set; 15 | 16 | /** 17 | * Created by jiang on 2016/10/9. 18 | */ 19 | 20 | public class JsonUtils { 21 | 22 | public static String getJson(final Bundle bundle) { 23 | if (bundle == null) return null; 24 | JSONObject jsonObject = new JSONObject(); 25 | 26 | for (String key : bundle.keySet()) { 27 | Object obj = bundle.get(key); 28 | try { 29 | jsonObject.put(key, wrap(bundle.get(key))); 30 | } catch (JSONException e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | return jsonObject.toString(); 35 | } 36 | 37 | private static Object wrap(Object o) { 38 | if (o == null) { 39 | return JSONObject.NULL; 40 | } 41 | if (o instanceof JSONArray || o instanceof JSONObject) { 42 | return o; 43 | } 44 | if (o.equals(JSONObject.NULL)) { 45 | return o; 46 | } 47 | try { 48 | if (o instanceof Collection) { 49 | return new JSONArray((Collection) o); 50 | } else if (o.getClass().isArray()) { 51 | return toJSONArray(o); 52 | } 53 | if (o instanceof Map) { 54 | return new JSONObject((Map) o); 55 | } 56 | if (o instanceof Boolean || 57 | o instanceof Byte || 58 | o instanceof Character || 59 | o instanceof Double || 60 | o instanceof Float || 61 | o instanceof Integer || 62 | o instanceof Long || 63 | o instanceof Short || 64 | o instanceof String) { 65 | return o; 66 | } 67 | if (o.getClass().getPackage().getName().startsWith("java.")) { 68 | return o.toString(); 69 | } 70 | } catch (Exception ignored) { 71 | } 72 | return null; 73 | } 74 | 75 | private static JSONArray toJSONArray(Object array) throws JSONException { 76 | JSONArray result = new JSONArray(); 77 | if (!array.getClass().isArray()) { 78 | throw new JSONException("Not a primitive array: " + array.getClass()); 79 | } 80 | final int length = Array.getLength(array); 81 | for (int i = 0; i < length; ++i) { 82 | result.put(wrap(Array.get(array, i))); 83 | } 84 | return result; 85 | } 86 | 87 | /** 88 | * 将map数据解析出来,并拼接成json字符串 89 | * 90 | * @param map 91 | * @return 92 | */ 93 | public static JSONObject setJson(Map map) throws Exception { 94 | JSONObject json = null; 95 | StringBuffer temp = new StringBuffer(); 96 | if (!map.isEmpty()) { 97 | temp.append("{"); 98 | // 遍历map 99 | Set set = map.entrySet(); 100 | Iterator i = set.iterator(); 101 | while (i.hasNext()) { 102 | Map.Entry entry = (Map.Entry) i.next(); 103 | String key = (String) entry.getKey(); 104 | Object value = entry.getValue(); 105 | temp.append("\"" ).append( key ).append( "\":"); 106 | if (value instanceof Map) { 107 | temp.append(setJson((Map) value) ).append( ","); 108 | } else if (value instanceof List) { 109 | temp.append(setList((List>) value) 110 | ).append( ","); 111 | } else { 112 | temp.append(value ).append( ","); 113 | } 114 | } 115 | if (temp.length() > 1) { 116 | temp = new StringBuffer(temp.substring(0, temp.length() - 1)); 117 | } 118 | temp.append("}"); 119 | json = new JSONObject(temp.toString()); 120 | } 121 | return json; 122 | } 123 | 124 | /** 125 | * 将单个list转成json字符串 126 | * 127 | * @param list 128 | * @return 129 | * @throws Exception 130 | */ 131 | private static String setList(List> list) 132 | throws Exception { 133 | String jsonL; 134 | StringBuffer temp = new StringBuffer(); 135 | temp.append("["); 136 | for (int i = 0; i < list.size(); i++) { 137 | Map m = list.get(i); 138 | if (i == list.size() - 1) { 139 | temp.append(setJson(m)); 140 | } else { 141 | temp.append(setJson(m) ).append( ","); 142 | } 143 | } 144 | if (temp.length() > 1) { 145 | temp = new StringBuffer(temp.substring(0, temp.length())); 146 | } 147 | temp.append("]"); 148 | jsonL = temp.toString(); 149 | return jsonL; 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/utils/L.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.utils; 2 | 3 | import android.util.Log; 4 | 5 | import com.jiang.android.push.BuildConfig; 6 | 7 | /** 8 | * Created by jiang on 2016/10/11. 9 | */ 10 | 11 | public class L { 12 | private static final String TAG = "AndroidPush"; 13 | 14 | public static final boolean debug = BuildConfig.DEBUG; 15 | 16 | public static void i(String msg) { 17 | //if (debug) { 18 | Log.i(TAG, msg); 19 | //} 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/utils/RomUtil.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.utils; 2 | 3 | import android.os.Build; 4 | import android.text.TextUtils; 5 | import android.util.Log; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStreamReader; 10 | 11 | /** 12 | * Created by jiang on 2016/10/8. 13 | */ 14 | 15 | public class RomUtil { 16 | private static Target mTarget = null; 17 | 18 | private static final String TAG = "RomUtil"; 19 | 20 | public static final String ROM_MIUI = "MIUI"; 21 | public static final String ROM_EMUI = "EMUI"; 22 | public static final String ROM_FLYME = "FLYME"; 23 | public static final String ROM_OPPO = "OPPO"; 24 | public static final String ROM_SMARTISAN = "SMARTISAN"; 25 | 26 | public static final String ROM_VIVO = "VIVO"; 27 | public static final String ROM_QIKU = "QIKU"; 28 | 29 | public static final String ROM_LENOVO = "LENOVO"; 30 | public static final String ROM_SAMSUNG = "SAMSUNG"; 31 | 32 | private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name"; 33 | private static final String KEY_VERSION_EMUI = "ro.build.version.emui"; 34 | private static final String KEY_VERSION_OPPO = "ro.build.version.opporom"; 35 | private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version"; 36 | private static final String KEY_VERSION_VIVO = "ro.vivo.os.version"; 37 | private static final String KEY_VERSION_GIONEE = "ro.gn.sv.version"; 38 | private static final String KEY_VERSION_LENOVO = "ro.lenovo.lvp.version"; 39 | private static final String KEY_VERSION_FLYME = "ro.build.display.id"; 40 | 41 | 42 | private static final String KEY_EMUI_VERSION_CODE = "ro.build.hw_emui_api_level"; 43 | 44 | private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code"; 45 | private static final String KEY_MIUI_HANDY_MODE_SF = "ro.miui.has_handy_mode_sf"; 46 | private static final String KEY_MIUI_REAL_BLUR = "ro.miui.has_real_blur"; 47 | 48 | private static final String KEY_FLYME_PUBLISHED = "ro.flyme.published"; 49 | private static final String KEY_FLYME_FLYME = "ro.meizu.setupwizard.flyme"; 50 | 51 | private static final String KEY_FLYME_ICON_FALG = "persist.sys.use.flyme.icon"; 52 | private static final String KEY_FLYME_SETUP_FALG = "ro.meizu.setupwizard.flyme"; 53 | private static final String KEY_FLYME_PUBLISH_FALG = "ro.flyme.published"; 54 | 55 | private static final String KEY_VIVO_OS_NAME = "ro.vivo.os.name"; 56 | private static final String KEY_VIVO_OS_VERSION = "ro.vivo.os.version"; 57 | private static final String KEY_VIVO_ROM_VERSION = "ro.vivo.rom.version"; 58 | 59 | public static boolean isEMUI() { 60 | return check(ROM_EMUI); 61 | } 62 | 63 | public static boolean isMIUI() { 64 | return check(ROM_MIUI); 65 | } 66 | 67 | public static boolean isVivo() { 68 | return check(ROM_VIVO); 69 | } 70 | 71 | public static boolean isOppo() { 72 | return check(ROM_OPPO); 73 | } 74 | 75 | public static boolean isFlyme() { 76 | return check(ROM_FLYME); 77 | } 78 | 79 | public static boolean isQiku() { 80 | return check(ROM_QIKU) || check("360"); 81 | } 82 | 83 | public static boolean isSmartisan() { 84 | return check(ROM_SMARTISAN); 85 | } 86 | 87 | private static String sName; 88 | 89 | public static String getName() { 90 | if (sName == null) { 91 | check(""); 92 | } 93 | return sName; 94 | } 95 | 96 | private static String sVersion; 97 | 98 | public static String getVersion() { 99 | if (sVersion == null) { 100 | check(""); 101 | } 102 | return sVersion; 103 | } 104 | 105 | public static boolean check(String rom) { 106 | if (sName != null) { 107 | return sName.equals(rom); 108 | } 109 | 110 | if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_MIUI))) { 111 | sName = ROM_MIUI; 112 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_EMUI))) { 113 | sName = ROM_EMUI; 114 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_OPPO))) { 115 | sName = ROM_OPPO; 116 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_VIVO))) { 117 | sName = ROM_VIVO; 118 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_SMARTISAN))) { 119 | sName = ROM_SMARTISAN; 120 | } else { 121 | sVersion = Build.DISPLAY; 122 | if (sVersion.toUpperCase().contains(ROM_FLYME)) { 123 | sName = ROM_FLYME; 124 | } else { 125 | sVersion = Build.UNKNOWN; 126 | sName = Build.MANUFACTURER.toUpperCase(); 127 | } 128 | } 129 | return sName.equals(rom); 130 | } 131 | 132 | public static String getProp(String name) { 133 | String line = null; 134 | BufferedReader input = null; 135 | try { 136 | Process p = Runtime.getRuntime().exec("getprop " + name); 137 | input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); 138 | line = input.readLine(); 139 | input.close(); 140 | } catch (IOException ex) { 141 | Log.e(TAG, "Unable to read prop " + name, ex); 142 | return null; 143 | } finally { 144 | if (input != null) { 145 | try { 146 | input.close(); 147 | } catch (IOException e) { 148 | e.printStackTrace(); 149 | } 150 | } 151 | } 152 | return line; 153 | } 154 | 155 | 156 | public static Target rom() { 157 | if (mTarget != null) 158 | return mTarget; 159 | 160 | if (isEMUI()) { 161 | mTarget = Target.EMUI; 162 | return mTarget; 163 | } 164 | if (isMIUI()) { 165 | mTarget = Target.MIUI; 166 | return mTarget; 167 | } 168 | if (isVivo()) { 169 | mTarget = Target.VIVO; 170 | return mTarget; 171 | } 172 | if (isOppo()) { 173 | mTarget = Target.OPPO; 174 | return mTarget; 175 | } 176 | mTarget = Target.JPUSH; 177 | return mTarget; 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/utils/Target.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.utils; 2 | 3 | /** 4 | * Created by jiang on 2016/10/8. 5 | */ 6 | 7 | public enum Target { 8 | MIUI, EMUI, FLYME, VIVO, OPPO, JPUSH 9 | } 10 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/vivo/PushMessageReceiverImpl.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.vivo; 2 | 3 | import android.content.Context; 4 | import android.text.TextUtils; 5 | import android.util.Log; 6 | 7 | import com.jiang.android.push.Message; 8 | import com.jiang.android.push.PushInterface; 9 | import com.jiang.android.push.utils.JHandler; 10 | import com.jiang.android.push.utils.JsonUtils; 11 | import com.jiang.android.push.utils.Target; 12 | import com.vivo.push.model.UPSNotificationMessage; 13 | import com.vivo.push.sdk.OpenClientPushMessageReceiver; 14 | 15 | public class PushMessageReceiverImpl extends OpenClientPushMessageReceiver { 16 | 17 | 18 | private static PushInterface mPushInterface; 19 | private String mMessage; 20 | 21 | /** 22 | * @param pushInterface 23 | */ 24 | public static void registerInterface(PushInterface pushInterface) { 25 | 26 | mPushInterface = pushInterface; 27 | } 28 | 29 | public static PushInterface getPushInterface() { 30 | return mPushInterface; 31 | } 32 | 33 | 34 | @Override 35 | public void onNotificationMessageClicked(final Context context, UPSNotificationMessage message) { 36 | mMessage = message.getContent(); 37 | 38 | if (mPushInterface != null) { 39 | final Message result = new Message(); 40 | result.setNotifyID(1); 41 | result.setMessageID(String.valueOf(message.getMsgId())); 42 | result.setTitle(message.getTitle()); 43 | result.setMessage(mMessage); 44 | result.setTarget(Target.MIUI); 45 | try { 46 | result.setExtra(JsonUtils.setJson(message.getParams()).toString()); 47 | } catch (Exception e) { 48 | Log.e(TAG, "onNotificationMessageClicked: " + e.toString()); 49 | result.setExtra("{}"); 50 | } 51 | JHandler.handler().post(new Runnable() { 52 | @Override 53 | public void run() { 54 | mPushInterface.onMessageClicked(context, result); 55 | } 56 | }); 57 | } 58 | } 59 | 60 | @Override 61 | public void onReceiveRegId(Context context, String s) { 62 | if (mPushInterface != null) { 63 | Message message = new Message(); 64 | message.setMessage(s); 65 | mPushInterface.onMessage(context, message); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /push/src/main/java/com/jiang/android/push/vivo/ViVOPushManager.java: -------------------------------------------------------------------------------- 1 | package com.jiang.android.push.vivo; 2 | 3 | import android.content.Context; 4 | 5 | import com.jiang.android.push.IPushManager; 6 | import com.jiang.android.push.PushInterface; 7 | import com.jiang.android.push.model.TokenModel; 8 | import com.jiang.android.push.utils.RomUtil; 9 | import com.vivo.push.IPushActionListener; 10 | import com.vivo.push.PushClient; 11 | 12 | public class ViVOPushManager implements IPushManager { 13 | @Override 14 | public void register(Context context, boolean debug, final PushInterface pushInterface) { 15 | // 在当前工程入口函数,建议在 Application 的 onCreate 函数中,添加以下代码: 16 | PushClient.getInstance(context).initialize(); 17 | // 当需要打开推送服务时,调用以下代码: 18 | PushClient.getInstance(context).turnOnPush(new IPushActionListener() { 19 | @Override 20 | public void onStateChanged(int i) { 21 | if (i == 0 && pushInterface != null) { 22 | PushMessageReceiverImpl.registerInterface(pushInterface); 23 | } 24 | 25 | } 26 | }); 27 | } 28 | 29 | @Override 30 | public void unregister(Context context) { 31 | PushClient.getInstance(context).turnOffPush(new IPushActionListener() { 32 | @Override 33 | public void onStateChanged(int i) { 34 | if (i == 0) { 35 | PushMessageReceiverImpl.registerInterface(null); 36 | } 37 | 38 | } 39 | }); 40 | 41 | } 42 | 43 | @Override 44 | public void setPushInterface(PushInterface pushInterface) { 45 | PushMessageReceiverImpl.registerInterface(pushInterface); 46 | 47 | } 48 | 49 | @Override 50 | public void setAlias(Context context, String alias) { 51 | PushClient.getInstance(context).bindAlias(alias, new IPushActionListener() { 52 | @Override 53 | public void onStateChanged(int i) { 54 | 55 | } 56 | }); 57 | } 58 | 59 | @Override 60 | public TokenModel getToken(Context context) { 61 | TokenModel result = new TokenModel(); 62 | result.setTarget(RomUtil.rom()); 63 | result.setToken(PushClient.getInstance(context).getRegId()); 64 | 65 | return result; 66 | } 67 | 68 | @Override 69 | public void pause(Context context) { 70 | 71 | PushClient.getInstance(context).turnOffPush(new IPushActionListener() { 72 | @Override 73 | public void onStateChanged(int i) { 74 | 75 | } 76 | }); 77 | if (PushMessageReceiverImpl.getPushInterface() != null) { 78 | PushMessageReceiverImpl.getPushInterface().onPaused(context); 79 | } 80 | } 81 | 82 | @Override 83 | public void resume(Context context) { 84 | register(context, false, null); 85 | if (PushMessageReceiverImpl.getPushInterface() != null) { 86 | PushMessageReceiverImpl.getPushInterface().onResume(context); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /push/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-hdpi/pushnotify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-hdpi/pushnotify.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-hdpi/send.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-hdpi/send.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-hdpi/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-hdpi/start.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-hdpi/upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-hdpi/upload.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ab_bottom_emui.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ab_bottom_emui.9.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_background_emui.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_background_emui.9.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_btn_check_off_emui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_btn_check_off_emui.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_btn_check_off_pressed_emui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_btn_check_off_pressed_emui.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_btn_check_on_emui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_btn_check_on_emui.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_btn_check_on_pressed_emui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_btn_check_on_pressed_emui.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_cancel.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_cancel_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_cancel_light.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_advance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_advance.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_back.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_collect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_collect.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_delete.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_multiple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_multiple.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_multiple1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_multiple1.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_ic_toolbar_refresh.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_list_activated_emui.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_list_activated_emui.9.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_list_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_list_icon.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_main_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_main_icon.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_no_collection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_no_collection.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_pic_ab_number.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_pic_ab_number.9.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_pic_ab_number_light.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_pic_ab_number_light.9.png -------------------------------------------------------------------------------- /push/src/main/res/drawable-xhdpi/hwpush_progress.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiang111/AndroidPush/33b0e1728f1eb63a976e0a43d0aeb20061465ab7/push/src/main/res/drawable-xhdpi/hwpush_progress.9.png -------------------------------------------------------------------------------- /push/src/main/res/layout/hwpush_buttons_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /push/src/main/res/layout/hwpush_collect_tip_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 26 | 27 | 37 | 38 | 39 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /push/src/main/res/layout/hwpush_collection_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 23 | 24 | 37 | 38 | 52 | 53 | 64 | 65 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /push/src/main/res/layout/hwpush_collection_listview.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 22 | 23 | 24 | 30 | 31 | 40 | 41 | 51 | 52 | 53 | 61 | 62 | 71 | 72 | 82 | 83 | 84 | 85 | 94 | 95 | 106 | 107 | 116 | 117 | 125 | 126 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 151 | 152 | 161 | 162 | 171 | 177 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /push/src/main/res/layout/hwpush_icons_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /push/src/main/res/layout/hwpush_layout2.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 28 | 29 | 38 | 39 | 49 | 50 | 62 | 63 | 64 |