Android集成vivo推送

①下载SDK,放到libs文件夹中。

②分别在gradle和AndroidManifest中配置好。

implementation files('libs/pushsdk_v2.3.4.jar') 
 <!--注册vivo推送--> <!--vivo推送配置项--> <meta-data android:name="com.vivo.push.api_key" android:value="xxxxxxxxxxxxx" /> <meta-data android:name="com.vivo.push.app_id" android:value="xxxxxxx" /> <!--推送服务需要配置的 service、activity--> <service android:name="com.vivo.push.sdk.service.CommandClientService" android:exported="true" /> <activity android:name="com.vivo.push.sdk.LinkProxyClientActivity" android:exported="false" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <!--注册vivo推送结束--> 

③在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<String,String> 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); } } 
<receiver android:name=".mctpush.vivoPush.VivoPushMessageReceiver"> <intent-filter> <!-- 接收push消息 --> <action android:name="com.vivo.pushclient.action.RECEIVE" /> </intent-filter> </receiver> 

到这里已经全部配置完成。

原文链接:https://blog.csdn.net/qq_33209777/article/details/122810888?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277698216782246456264%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277698216782246456264&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-4-122810888-null-null.nonecase&utm_term=vivo

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片

    暂无评论内容