package com.yeshi.push;
|
|
import android.app.ActivityManager;
|
import android.app.Application;
|
import android.content.Context;
|
import android.os.Build;
|
import android.os.Process;
|
import android.util.Log;
|
|
import com.heytap.msp.push.HeytapPushManager;
|
import com.heytap.msp.push.callback.ICallBackResultService;
|
import com.lcjian.library.util.ManifestDataUtil;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.meizu.cloud.pushsdk.PushManager;
|
import com.vivo.push.IPushActionListener;
|
import com.vivo.push.PushClient;
|
import com.xiaomi.mipush.sdk.MiPushClient;
|
|
import java.util.List;
|
|
public class PushUtil {
|
|
static String TAG = "PushUtil";
|
|
/**
|
* 推送 注册
|
*/
|
public static void inintPush(Application context, ITokenListener tokenListener) {
|
if (context != null) {
|
String xmRegId = null;
|
switch (Build.BRAND.toLowerCase()) {
|
case "huawei":
|
case "honor":
|
//华为是自动初始化
|
return;
|
case "oppo"://上面官方判断
|
/***OPPO官方判断方法*/
|
HeytapPushManager.init(context, true);
|
if (HeytapPushManager.isSupportPush()) {
|
String appKey = ManifestDataUtil.getAppMetaData(context, "OPPO_APPKEY").replace("OPPO-", "");
|
String appSecret = ManifestDataUtil.getAppMetaData(context, "OPPO_APPSECRET").replace("OPPO-", "");
|
HeytapPushManager.register(context, appKey, appSecret, new ICallBackResultService() {
|
|
@Override
|
public void onRegister(int i, String s) {
|
//注册成功
|
Log.i(TAG, "OPPO注册结果:" + i);
|
Log.i(TAG, "OPPO注册成功:" + s);
|
if (i == 0) {
|
tokenListener.onToken("oppo", s);
|
}
|
}
|
|
@Override
|
public void onUnRegister(int i) {
|
|
}
|
|
@Override
|
public void onSetPushTime(int i, String s) {
|
|
}
|
|
@Override
|
public void onGetPushStatus(int i, int i1) {
|
|
}
|
|
@Override
|
public void onGetNotificationStatus(int i, int i1) {
|
|
}
|
});
|
HeytapPushManager.requestNotificationPermission();
|
return;
|
}
|
break;
|
case "vivo"://上面官方判断
|
/***VIVO官方判断方法**/
|
// 在当前工程入口函数,建议在 Application 的 onCreate 函数中,添加以下代码:
|
PushClient.getInstance(context).initialize();
|
if (PushClient.getInstance(context).isSupport()) {
|
//并且打开推送服务
|
PushClient.getInstance(context).turnOnPush(new IPushActionListener() {
|
@Override
|
public void onStateChanged(int i) {
|
if (i == 0) {
|
String regId = PushClient.getInstance(context).getRegId();
|
Log.i(TAG, "VIVO注册成功:" + regId);
|
tokenListener.onToken("vivo", regId);
|
}
|
}
|
});
|
return;
|
}
|
break;
|
case "meizu"://魅族
|
{
|
String appId = ManifestDataUtil.getAppMetaData(context, "MEIZU_APPID").replace("MEIZU-", "");
|
String appKey = ManifestDataUtil.getAppMetaData(context, "MEIZU_APPKEY").replace("MEIZU-", "");
|
PushManager.register(context, appId, appKey);
|
return;
|
}
|
}
|
|
String appId = ManifestDataUtil.getAppMetaData(context, "XIAOMI_APPID").replace("XIAOMI-", "");
|
String appKey = ManifestDataUtil.getAppMetaData(context, "XIAOMI_APPKEY").replace("XIAOMI-", "");
|
MiPushClient.registerPush(context, appId, appKey);//注册小米推送
|
xmRegId = MiPushClient.getRegId(context);
|
Log.i(TAG, "小米注册成功:" + xmRegId);
|
if (!StringUtils.isEmpty(xmRegId)) {
|
tokenListener.onToken("xm", xmRegId);
|
}
|
|
|
}
|
}
|
|
|
public interface ITokenListener {
|
public void onToken(String romType, String regId);
|
|
}
|
|
}
|