feat: 消息推送:接入阿里云消息推送系统—客户端 https://jira.shanqu.cc/browse/GHZS-4941
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.halo.assistant;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -50,6 +51,7 @@ import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.Injection;
|
||||
import com.gh.gamecenter.common.constant.Config;
|
||||
import com.gh.gamecenter.common.constant.Constants;
|
||||
import com.gh.gamecenter.common.constant.RouteConsts;
|
||||
import com.gh.gamecenter.common.exposure.meta.MetaUtil;
|
||||
import com.gh.gamecenter.common.image.EmptyDecoder;
|
||||
import com.gh.gamecenter.common.tracker.Tracker;
|
||||
@ -63,9 +65,12 @@ import com.gh.gamecenter.common.utils.SensorsBridge;
|
||||
import com.gh.gamecenter.core.AppExecutor;
|
||||
import com.gh.gamecenter.core.iinterface.IApplication;
|
||||
import com.gh.gamecenter.core.provider.IFlavorProvider;
|
||||
import com.gh.gamecenter.core.provider.IPushProvider;
|
||||
import com.gh.gamecenter.core.utils.DisplayUtils;
|
||||
import com.gh.gamecenter.core.utils.GsonUtils;
|
||||
import com.gh.gamecenter.core.utils.SPUtils;
|
||||
import com.gh.gamecenter.entity.SubjectRecommendEntity;
|
||||
import com.gh.gamecenter.login.user.UserManager;
|
||||
import com.gh.gamecenter.login.user.UserRepository;
|
||||
import com.gh.gamecenter.oaid.OAIDHelper;
|
||||
import com.gh.gamecenter.packagehelper.PackageRepository;
|
||||
@ -89,7 +94,10 @@ import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager;
|
||||
import tv.danmaku.ijk.media.exo2.ExoPlayerCacheManager;
|
||||
|
||||
@ -252,6 +260,9 @@ public class HaloApp extends MultiDexApplication {
|
||||
deviceRamSize = DeviceUtils.getTotalRamSizeOfDevice(this);
|
||||
mChannel = mFlavorProvider.getChannelStr(this);
|
||||
|
||||
// 初始化阿里云推送
|
||||
ExtensionsKt.doOnMainProcessOnly(this, this::initPushEngine);
|
||||
|
||||
// 异步初始化 SP
|
||||
SPUtils.getString("");
|
||||
});
|
||||
@ -314,6 +325,8 @@ public class HaloApp extends MultiDexApplication {
|
||||
MetaUtil.INSTANCE.refreshMeta();
|
||||
SensorsBridge.INSTANCE.setOAID(s);
|
||||
|
||||
registerPushEngine();
|
||||
|
||||
// 上报设备安装事件
|
||||
if (isNewForThisVersion) {
|
||||
final LunchType launchType = getLaunchType();
|
||||
@ -435,6 +448,61 @@ public class HaloApp extends MultiDexApplication {
|
||||
this.registerReceiver(skipReceiver, skipFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化推送
|
||||
*/
|
||||
private void initPushEngine() {
|
||||
IPushProvider pushProvider = (IPushProvider) ARouter
|
||||
.getInstance()
|
||||
.build(RouteConsts.provider.push)
|
||||
.navigation();
|
||||
pushProvider.initialize(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同意隐私政策后,注册推送功能
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void registerPushEngine() {
|
||||
IPushProvider pushProvider = (IPushProvider) ARouter
|
||||
.getInstance()
|
||||
.build(RouteConsts.provider.push)
|
||||
.navigation();
|
||||
|
||||
// 绑定账号
|
||||
Single<String> bindAccountSingle = pushProvider.bindAccount(getOAID());
|
||||
|
||||
// 绑定标签
|
||||
Single<String> bindTagSingle = pushProvider.bindTag(mChannel)
|
||||
.subscribeOn(Schedulers.io());
|
||||
|
||||
// 初始化推送
|
||||
pushProvider
|
||||
.register(this)
|
||||
.flatMap((response) -> {
|
||||
// 绑定别名、标签和账号任意一个流程失败,都不会影响其他流程的执行
|
||||
Single<String> single = bindAccountSingle
|
||||
.onErrorReturn((e) -> response)
|
||||
.zipWith(bindTagSingle.onErrorReturn((e) -> response), (s1, s2) -> response);
|
||||
if (UserManager.getInstance().isLoggedIn()) {
|
||||
String userId = UserManager.getInstance().getUserId();
|
||||
// 绑定别名
|
||||
Single<String> bindAliasSingle = pushProvider
|
||||
.bindAlias(userId)
|
||||
.subscribeOn(Schedulers.io());
|
||||
single = single.zipWith(bindAliasSingle.onErrorReturn((e) -> response), (s1, s2) -> response);
|
||||
}
|
||||
return single;
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
s -> Utils.log("IPushProvider->init push succeed, response: " + s + ",channel: " + getChannel()),
|
||||
e -> Utils.log("IPushProvider->init push failed, error: " + e + ", channel: " + getChannel())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void initPackageChangesReceiver() {
|
||||
InstallAndUninstallReceiver receiver = new InstallAndUninstallReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
|
||||
Reference in New Issue
Block a user