①下载SDK,放到libs文件夹中。
image.png
②分别在gradle和AndroidManifest中配置好。
implementation files('libs/pushsdk_v2.3.4.jar')
android:name="com.vivo.push.api_key"
android:value="xxxxxxxxxxxxx" />
android:name="com.vivo.push.app_id"
android:value="xxxxxxx" />
android:name="com.vivo.push.sdk.service.CommandClientService"
android:exported="true" />
android:name="com.vivo.push.sdk.LinkProxyClientActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
③在application中初始化
/**
* 初始化vivo推送
*/
public static void initVivoPush(Context context) {
//初始化vivo推送
PushClient.getInstance(context).initialize();
//并且打开推送服务
PushClient.getInstance(context).turnOnPush(new IPushActionListener() {
@Override
public void onStateChanged(int i) {
if (i == 0) {
Log.e("NPL", "打开推送服务成功");
} else {
Log.e("NPL", "打开推送服务失败");
}
}
});
}
④编写receiver并在AndroidMenifest中注册
public class VivoPushMessageReceiver extends OpenClientPushMessageReceiver {
private int nativeRedirect=0;
private String url="";
private int pageType=0;
private int newsType=0;
private long newsId=0;
private String thumb="";
private String title = "";
private String content = "";
@Override
public void onNotificationMessageClicked(Context context, UPSNotificationMessage upsNotificationMessage) {
title = upsNotificationMessage.getTitle();
content = upsNotificationMessage.getContent();
Map map = upsNotificationMessage.getParams();
if (map.get(MessageEntity.NativeRedirect)!=null&&!map.get(MessageEntity.NativeRedirect).equals("")){
nativeRedirect = Integer.valueOf(map.get(MessageEntity.NativeRedirect));
}
url = map.get(MessageEntity.Link);
if (map.get(MessageEntity.PageType)!=null&&!map.get(MessageEntity.PageType).equals("")){
pageType = Integer.valueOf(map.get(MessageEntity.PageType));
}
if (map.get(MessageEntity.NewsType)!=null&&!map.get(MessageEntity.NewsType).equals("")){
newsType = Integer.valueOf(map.get(MessageEntity.NewsType));
}
if (map.get(MessageEntity.NewsId)!=null&&!map.get(MessageEntity.NewsId).equals("")){
newsId = Long.valueOf(map.get(MessageEntity.NewsId));
}
thumb = map.get(MessageEntity.Thumb);
}
@Override
public void onReceiveRegId(Context context, String s) {
SpUtil.saveNoClearString(context, SpKey.VIVO_PUSH_REGISTRATION_ID, s);
}
}
到这里已经全部配置完成。