消息推送SDK快速集成:
申请AppKey ——> 接入Push SDK ——> 基础接口引入 ——> 消息推送测试 ——> 接入完成java
1.申请AppKey
2.接入Push SDK
android
1)、加入依赖app
//友盟push相关依赖(必须) implementation'com.umeng.umsdk:push:6.1.0' implementation'com.umeng.umsdk:alicloud-httpdns:1.2.5' implementation'com.umeng.umsdk:alicloud-utils:1.1.5' implementation'com.umeng.umsdk:alicloud_beacon:1.0.1' implementation'com.umeng.umsdk:agoo-accs:3.3.8.8-open-fix2' implementation'com.umeng.umsdk:agoo_networksdk:3.5.5' implementation'com.umeng.umsdk:agoo_tlog:3.0.0.17' implementation'com.umeng.umsdk:agoo_tnet4android:3.1.14.9' implementation'com.umeng.umsdk:asms:1.1.3' implementation'com.umeng.umsdk:crash:0.0.4'
2)、在工程build.gradle配置脚本中buildscript和allprojects段中添加【友盟+】sdk 新maven仓库地址maven
buildscript { repositories { google() jcenter() maven { url 'https://dl.bintray.com/umsdk/release' } } dependencies { classpath 'com.android.tools.build:gradle:3.1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() mavenCentral() maven { url 'https://dl.bintray.com/umsdk/release' } } }
3)、在AndroidManifest.xml文件中引入相关基础组件:ide
<!-- 如下为基本配置信息,须要自行添加至您的AndroidManifest文件中 start--> <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> <intent-filter> <action android:name="com.taobao.accs.intent.action.ELECTION" /> </intent-filter> </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="com.taobao.accs.internal.AccsJobService" android:permission="android.permission.BIND_JOB_SERVICE" android:process=":channel"/> <service android:name="com.taobao.accs.ChannelService$KernelService" android:process=":channel" /> <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.umeng.message.UmengIntentService" android:exported="true" android:process=":channel"> <intent-filter> <action android:name="org.agoo.android.intent.action.RECEIVE" /> </intent-filter> </service> <service android:name="com.umeng.message.XiaomiIntentService" android:exported="true" android:process=":channel"> <intent-filter> <action android:name="org.agoo.android.intent.action.RECEIVE" /> </intent-filter> </service> <receiver android:name="com.taobao.agoo.AgooCommondReceiver" android:exported="true" android:process=":channel"> <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> <service android:name="com.umeng.message.UmengMessageIntentReceiverService" android:exported="true" android:process=":channel"> <intent-filter> <action android:name="org.android.agoo.client.MessageReceiverService" /> </intent-filter> </service> <receiver android:name="com.umeng.message.NotificationProxyBroadcastReceiver" android:exported="false" /> <service android:name="com.umeng.message.UmengMessageCallbackHandlerService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"> <intent-filter> <action android:name="com.umeng.messge.registercallback.action" /> </intent-filter> <intent-filter> <action android:name="com.umeng.message.enablecallback.action" /> </intent-filter> <intent-filter> <action android:name="com.umeng.message.disablecallback.action" /> </intent-filter> <intent-filter> <action android:name="com.umeng.message.message.handler.action" /> </intent-filter> <intent-filter> <action android:name="com.umeng.message.message.sendmessage.action" /> </intent-filter> </service> <service android:name="com.umeng.message.UmengDownloadResourceService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false" /> <provider android:name="com.umeng.message.provider.MessageProvider" android:authorities="${applicationId}.umeng.message" android:exported="false"> <grant-uri-permission android:pathPattern=".*" /> </provider> <!-- 如下为基本配置信息,须要自行添加至您的AndroidManifest文件中 end-->
4)、引入so文件 (全平台so文件下载地址)
注意:这边下载的so文件可能会少,最好分方法就是直接吧友盟demo中libs的文件全粘进去(开发者Demo)
布局
5)、’引入默认通知栏通知样式布局文件(开发者Demo)测试
upush_bar_image_notification.xml
upush_notification.xml
gradle
3.基础接口引入ui
1).在工程的MyApplication类的 onCreate() 方法中作SDK代码初始化工做。
UMConfigure.init(this, “替换为Appkey,服务后台位置:应用管理 -> 应用信息 -> Appkey”, “Umeng”, UMConfigure.DEVICE_TYPE_PHONE, “替换为秘钥信息,服务后台位置:应用管理 -> 应用信息 -> Umeng Message Secret”);
this
//获取消息推送代理示例 PushAgent mPushAgent = PushAgent.getInstance(this); //注册推送服务,每次调用register方法都会回调该接口 mPushAgent.register(new IUmengRegisterCallback() { @Override public void onSuccess(String deviceToken) { //注册成功会返回deviceToken deviceToken是推送消息的惟一标志 Log.i(TAG,"注册成功:deviceToken:--------> " + deviceToken); } @Override public void onFailure(String s, String s1) { Log.e(TAG,"注册失败:--------> " + "s:" + s + ",s1:" + s1); } });
deviceToken是【友盟+】消息推送生成的用于标识设备的id,长度为44位,不能定制和修改。同一台设备上不一样应用对应的deviceToken不同。获取deviceToken的值后,可进行消息推送测试!
2).应用数据统计接口
在全部的Activity 的onCreate 方法或在应用的BaseActivity的onCreate方法中添加:
PushAgent.getInstance(context).onAppStart();
注:该方法是【友盟+】Push后台进行日活统计及多维度推送的必调用方法,请务必调用!
4.消息推送测试
顺利获取deviceToken!咱们立刻能够向这台设备推送消息了~
添加测试设备:
在【友盟+】消息推送服务Push后台的“测试模式”中填写获取到的deviceToken,将该设备添加为测试设备:
在测试消息中新建消息,详细过程以下所示,详细过程以下所示:
5.接入完成
此时在您的测试手机上能够看到您刚才的推送消息!