消息推送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.接入完成
此時在您的測試手機上能夠看到您剛纔的推送消息!