一键集成华为,小米,oppo,vivo,umeng推送
2020-04-16 本文已影响0人
浪够_
最近把项目的push模块做了抽离,并开源到了jcenter库中,需要集成的可一键集成到项目中,后续会定时更新。
该库集成了华为,小米,oppo,vivo等厂商,umeng第三方的消息推送,开发者可一键集成,稳定,方便,快捷,该库优先厂商通道,对于非此四家的手机平台,将默认走umeng通道
github地址:https://github.com/shixiangyu/multi-push
Setup
1.Download
Edit your build.gradle file, add dependencies in your gradle:
implementation 'com.xiangyu:multi-push:1.0.0'
- Configurate AppId
在自己的项目清单文件AndroidManifest.xml中声明各平台的appkey,appid
<meta-data
<!--umeng key-->
android:name="UMENG_APPKEY"
android:value="@string/umeng_app_key" />
<meta-data
android:name="UMENG_MESSAGE_SECRET"
android:value="@string/umeng_app_secret" />
<!--umeng key end-->
<!--huawei key-->
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="@string/huawei_app_id" />
<!--huawei key end-->
<!--vivo key-->
<meta-data
android:name="com.vivo.push.app_id"
android:value="@string/vivo_app_id" />
<meta-data
android:name="com.vivo.push.api_key"
android:value="@string/vivo_api_key" />
<!--vivo key end-->
<!--xiaomi key-->
<meta-data
android:name="com.xiaomi.mipush.app_id"
android:value="@string/mi_app_id" />
<meta-data
android:name="com.xiaomi.mipush.app_key"
android:value="@string/mi_app_key" />
<!--xiaomi key end-->
<!--oppo key-->
<meta-data
android:name="com.heytap.oppopush.app_key"
android:value="@string/oppo_app_key" />
<meta-data
android:name="com.heytap.oppopush.app_secret"
android:value="@string/oppo_app_secret" />
<!--oppo key end-->
之后在工程的res/values/strings.xml中声明对应的值,如
<!-- app id and key-->
<string name="huawei_app_id">xxxxxx</string>
<string name="mi_app_id">xxxxxx</string>
<string name="mi_app_key">xxxxxx</string>
<string name="oppo_app_key">xxxxxx</string>
<string name="oppo_app_secret">xxxxxx</string>
<string name="vivo_app_id">xxxxxx</string>
<string name="vivo_api_key">xxxxxx</string>
<string name="umeng_app_key">xxxxxx</string>
<string name="umeng_app_secret">xxxxxx</string>
<!-- app id and key end-->
2.Initialize
placing the initialization in your Application
kotlin
WDPushManager.initialize(this,object :IPushHandler{
override fun onNotificationMessageClicked(context: Context, action: String) {
//action:服务端下发的动作action
//To change body of created functions.
}
override fun onReceiveToken(context: Context, deviceType: String, token: String) {
//To change body of created functions.
// token:注册成功后返回的token,上报给自己的服务端
//To change body of created functions.
}
} )
java
WDPushManager.INSTANCE.initialize(getApplication(), new IPushHandler() {
@Override
public void onNotificationMessageClicked(@NotNull Context context, @NotNull String action) {
//action:服务端下发的动作action
//To change body of created functions.
}
@Override
public void onReceiveToken(@NotNull Context context, @NotNull String deviceType, @NotNull String token) {
//deviceType:手机类型,有"huawei","xiaomi","vivo","oppo","umeng"五种,可上报自己的服务端,用于区分不同渠道
// token:注册成功后返回的token,上报给自己的服务端
//To change body of created functions.
}
});
集成完毕!