Android 阿里云推送集成指南
一、注册阿里云开发者账号,创建应用获取Appkey以及AppSecrent
二、在AndroidMainifest添加权限,还有一些其他权限(基本上你自己的项目已经写了,我就不贴了)
<uses-permission android:name="android.permission.WRITE_SETTINGS"tools:ignore="ProtectedPermissions" /> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RESTART_PACKAGES" /> <uses-permission android:name="android.permission.REORDER_TASKS" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"tools:ignore="ProtectedPermissions" />
android:allowBackup="true"在Application加上这个属性。
三、在build.gradle中引入阿里云推送库(根据官方文档的引入就一个的会有问题,亲测这种是最保险的)
implementation 'com.aliyun.ams:alicloud-android-push:3.1.4@aar' implementation 'com.aliyun.ams:alicloud-android-utils:1.1.3' implementation 'com.aliyun.ams:alicloud-android-beacon:1.0.1' implementation 'com.aliyun.ams:alicloud-android-ut:5.4.0'
设置ndk支持so包,abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'其实国内手机99%以上都是arm的,
就支持arm就可以了,这样也能减小apk体积,因为so的体积确实不小,每个项目都适用。
在gradle.properties加入android.useDeprecatedNdk=true
四、在AndroidMainifest中加入以下,阿里云的配置
<meta-data android:name="com.alibaba.app.appkey" android:value="yourKey"/> <!-- 请填写你自己的- appKey --> <meta-data android:name="com.alibaba.app.appsecret" android:value="yourAppsecret"/> <!-- 请填写你自己的appSecret --> <!-- Push SDK 相关组件,required--> <!-- 消息接收服务 --> <serviceandroid:name="com.alibaba.sdk.android.push.MsgService"android:exported="false"><intent-filter><action android:name="com.alibaba.sdk.android.push.NOTIFY_ACTION" /></intent-filter> </service> <service android:name="com.alibaba.sdk.android.push.channel.CheckService"android:process=":channel"><intent-filter><action android:name="com.alibaba.sdk.android.push.CHECK_SERVICE" /></intent-filter> </service> <service android:name="com.taobao.accs.ChannelService"android:exported="true" android:process=":channel"><intent-filter><action android:name="com.taobao.accs.intent.action.SERVICE"/></intent-filter> </service> <serviceandroid:name="com.taobao.accs.ChannelService$KernelService"android:exported="false"android:process=":channel" > </service> <service android:name="com.taobao.accs.data.MsgDistributeService"android:exported="true"><intent-filter><action android:name="com.taobao.accs.intent.action.RECEIVE" /></intent-filter> </service> <receiver android:name="com.taobao.accs.EventReceiver"android:process=":channel"><intent-filter><action android:name="android.intent.action.BOOT_COMPLETED"/></intent-filter><intent-filter><action android:name="android.net.conn.CONNECTIVITY_CHANGE"/></intent-filter><intent-filter><action android:name="android.intent.action.PACKAGE_REMOVED"/><data android:scheme="package"/></intent-filter><intent-filter><action android:name="android.intent.action.USER_PRESENT"/></intent-filter> </receiver> <receiver android:name="com.taobao.accs.ServiceReceiver"android:process=":channel"><intent-filter><action android:name="com.taobao.accs.intent.action.COMMAND"/></intent-filter><intent-filter><action android:name="com.taobao.accs.intent.action.START_FROM_AGOO"/></intent-filter> </receiver> <service android:name="org.android.agoo.accs.AgooService"android:exported="true" ><intent-filter><action android:name="com.taobao.accs.intent.action.RECEIVE" /></intent-filter> </service> <service android:name="com.alibaba.sdk.android.push.AliyunPushIntentService"android:exported="true"><intent-filter><action android:name="org.agoo.android.intent.action.RECEIVE" /></intent-filter> </service> <receiverandroid:name="com.taobao.agoo.AgooCommondReceiver"android:process=":channel"android:exported="true" ><intent-filter><action android:name="${applicationId}.intent.action.COMMAND" /></intent-filter><intent-filter><action android:name="android.intent.action.PACKAGE_REMOVED" /><data android:scheme="package" /></intent-filter> </receiver> <serviceandroid:name="com.alibaba.sdk.android.push.channel.TaobaoRecvService"android:exported="true"android:process=":channel"><intent-filter><action android:name="org.android.agoo.client.MessageReceiverService" /></intent-filter> </service> <!-- V3.0.12及以上版本需配置 --> <serviceandroid:name="com.taobao.accs.internal.AccsJobService"android:permission="android.permission.BIND_JOB_SERVICE"android:process=":channel"/> <!-- V3.0.7及以上版本需配置 --> <service android:name="com.alibaba.sdk.android.push.channel.KeepChannelService"android:permission="android.permission.BIND_JOB_SERVICE"android:process=":channel" /> <receiver android:name="com.alibaba.sdk.android.push.SystemEventReceiver"android:process=":channel"><intent-filter><action android:name="android.intent.action.MEDIA_MOUNTED"/><action android:name="android.intent.action.ACTION_POWER_CONNECTED"/><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/></intent-filter> </receiver> <!-- V3.0.9及以上版本需配置 --> <activityandroid:name="com.alibaba.sdk.android.push.keeplive.PushExtActivity"android:configChanges="keyboardHidden|orientation|screenSize|navigation|keyboard"android:excludeFromRecents="true"android:exported="false"android:finishOnTaskLaunch="false"android:launchMode="singleInstance"android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"android:process=":channel"> </activity> <!-- 消息接收监听器 (用户可自主扩展) --> <receiverandroid:name=".receiver.MyMessageReceiver"android:exported="false"> <!-- 为保证receiver安全,建议设置不可导出,如需对其他应用开放可通过android:permission进行限制 --><intent-filter><action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" /></intent-filter><intent-filter><action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" /></intent-filter><intent-filter><action android:name="com.alibaba.sdk.android.push.RECEIVE" /></intent-filter> </receiver>
五、在Application中初始化阿里云推送
/*** 初始化云推送通道* @param applicationContext*/ private void initCloudChannel(Context applicationContext) {createNotificationChannel();PushServiceFactory.init(applicationContext);CloudPushService pushService = PushServiceFactory.getCloudPushService();pushService.register(applicationContext, new CommonCallback() {@Overridepublic void onSuccess(String response) {String deviceId = PushServiceFactory.getCloudPushService().getDeviceId();Log.e(TAG,deviceId);Log.d(TAG, "init cloudchannel success");}@Overridepublic void onFailed(String errorCode, String errorMessage) {Log.d(TAG, "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);}});} private void createNotificationChannel(){if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);// 通知渠道的idString id = "1";//这个是与后台约定好的,要不收不到,该方法主要是适配Android 8.0以上,避免接收不到通知// 用户可以看到的通知渠道的名字.CharSequence name = "氢氪管家";// 用户可以看到的通知渠道的描述String description = "管理氢氪车辆";int importance = NotificationManager.IMPORTANCE_HIGH;NotificationChannel mChannel = new NotificationChannel(id, name, importance);// 配置通知渠道的属性mChannel.setDescription(description);// 设置通知出现时的闪灯(如果 android 设备支持的话)mChannel.enableLights(true);mChannel.setLightColor(Color.RED);// 设置通知出现时的震动(如果 android 设备支持的话)mChannel.enableVibration(true);mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});//最后在notificationmanager中创建该通知渠道mNotificationManager.createNotificationChannel(mChannel);} }
六、自定义MyMessageReceiver
public class MyMessageReceiver extends MessageReceiver {// 消息接收部分的LOG_TAGpublic static final String REC_TAG = "receiver";@Overridepublic void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {//当通知准确到达用户的时候触发ToastManage.s(context,title+"推送");Log.e("MyMessageReceiver", "Receive notification, title: " + title + ", summary: " + summary + ", extraMap: " + extraMap);}@Overridepublic void onMessage(Context context, CPushMessage cPushMessage) {//当消息准确到达用户的时候触发,只有用户在使用的时候才能接收到消息Log.e("MyMessageReceiver", "onMessage, messageId: " + cPushMessage.getMessageId() + ", title: " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());ToastManage.s(context,"消息:"+cPushMessage.getTitle());}@Overridepublic void onNotificationOpened(Context context, String title, String summary, String extraMap) {//当通知展开的时候触发的操作Log.e("MyMessageReceiver", "onNotificationOpened, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);ToastManage.s(context,"打开了通知:"+title);}@Overrideprotected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {//当通知被点击了触发的操作,并且没有配置跳转路径ToastManage.s(context,"onNotificationClickedWithNoAction, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);Log.e("MyMessageReceiver", "onNotificationClickedWithNoAction, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);}@Overrideprotected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {//当用户使用时接收到通知ToastManage.s(context,"onNotificationReceivedInApp, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap + ", openType:" + openType + ", openActivity:" + openActivity + ", openUrl:" + openUrl);Log.e("MyMessageReceiver", "onNotificationReceivedInApp, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap + ", openType:" + openType + ", openActivity:" + openActivity + ", openUrl:" + openUrl);}@Overrideprotected void onNotificationRemoved(Context context, String messageId) {//通知被移除ToastManage.s(context,"通知被移除了");Log.e("MyMessageReceiver", "onNotificationRemoved");} }
Android 阿里云推送集成指南相关推荐
- Android 阿里云推送,针对安卓8.0、9.0以上系统收不到推送 的补丁文档
官方的文档地址: Android 8.0以上: https://help.aliyun.com/knowledge_detail/67398.html Android 9.0以上: https://h ...
- Android集成阿里云推送功能
官方集成参考网址:https://help.aliyun.com/document_detail/51056.html?spm=a2c4g.11186623.6.587.64ed7fa8NY9DN8 ...
- ionic集成阿里云推送
阿里云推送是比较廉价,快速的推送管理平台,目前在ionic上有一个插件可以直接使用它,不需要官网介绍的那些复杂步骤.插件地址:https://github.com/llwwbb/cordova-plu ...
- 阿里云推送 AndroidSDK 3.0 快速集成
文章目录 0.控制台中配置好产品应用 1. 基础接入配置使用 1.1配置根目录的 build.gradle文件 1.2配置要接入module的build.gradle文件 1.3配置清单文件 2. 接 ...
- Android百度云推送接入,附完整代码
1.创建应用获取api_key 百度云推送:http://push.baidu.com/ SDK下载:http://push.baidu.com/sdk/push_client_sdk_for_and ...
- java服务器端集成友盟,Android友盟推送集成
第一次认真集成推送,碰到了一些问题,记录一下. 首先讲一下实现原理,我们用的是友盟.Android比iOS要麻烦很多. 友盟集成是需要后端配合的,具体就是后端调用友盟的接口,向友盟推送一条消息,然后友 ...
- 基于android百度云推送务设计,Android之基于百度云推送IM
偶然的一天,发现百度出了一个云推送包,想想百度的服务器还是比较靠谱的说,怎么着也比我们自己搭建的服务器要稳定,于是乎,我就花了几天时间,写了一个小小的聊天工具,权当是练手.主要思路是:客户端的聊天内容 ...
- react-native集成阿里云推送
1.使用组件 react-native-aliyun-push 2.安装及集成 *注意在之前必须要到阿里云注册移动推送服务并建好ios和android的app,里面的appkey和AppSecret到 ...
- 阿里云推送 SDK iOS 端 配置
阿里云 SDK 配置 请依官方为主,毕竟已经很详细了 https://help.aliyun.com/document_detail/30072.html?spm=5176.doc30071.6.64 ...
- 影视网站之发送阿里云推送邮件教程
阿里云邮件推送确实不错,其他的云厂商暂时没发现有这种推送邮件的功能,每个用户每天有200封免费发送的邮件,也可以进行付费购买.其实很早之前就使用过这个邮件进行推送,为了方便以后去熟悉这个繁琐的过程,记 ...
最新文章
- 2021 Facebook 博士奖研金名单出炉:13位华人学者获选
- python 材料科学与工程专业_2020年最全的python的就业方向+清华计算机社流出上千集编程资料...
- OpenCV之feature2d 模块. 2D特征框架(1)Harris 角点检测子 Shi-Tomasi角点检测子 定制化创建角点检测子 亚像素级的角点检测 特征点检测
- java实现大整数的加减乘除法(百练OJ:2736、2737、2980、2981)
- 备案号链接工信部_工信部备案系统启用新域名
- Spark1.4 和 Hive 1.1.1 启动错误
- 5.16-在线词识别程序学习(ASR+IAT)
- Opportunity retrieval in SalesPipeline
- LeetCode 36. 有效的数独(哈希)
- HTML的文本格式化
- 企业域名备案流程_2021境外投资备案申报流程(办理企业境外投资证书注意事项)...
- QT5开发及实例学习之十六Qt5基础图形的绘制
- 小米11顶配版屏幕参数曝光:2K 120Hz高刷屏支持运动补偿
- 【PHP】Ajax跨域解决方案 、jsonp、cors
- 关于ObjectProxy
- iptables与Netfilter概念
- nginx实现rtmp,flv,mp4流媒体服务器
- Excel 自动生成排名 RANK函数的使用
- 树莓派cups搭建无线打印机(HP Laserjet 1020)
- 剑指 Offer 42. 连续子数组的最大和(官解)
热门文章
- android游戏录音,音频录音剪辑软件 1.1.15 安卓版
- HTML5游子吟网页的完整代码,游子吟
- OS X: 实用脚本程序(bash scripts)系列-14
- java httpclient重定向_HTTPClient重定向
- 计算机一级excel函数rank函数应用,2017年计算机一级excel操作题
- Python-振动信号加入噪声-代码实现
- 如何在Java中将Excel(XLSX)转换为Word(DOCX)
- Win11 Windows聚焦失效修复方法
- ★【博弈论】【贝蒂定理】取棋子游戏
- Dhtmlx Gantt 快速入门至精通