package com.yeshi.push;
|
|
import android.app.Application;
|
import android.os.Build;
|
import android.util.Log;
|
|
import com.heytap.msp.push.HeytapPushManager;
|
import com.heytap.msp.push.callback.ICallBackResultService;
|
import com.meizu.cloud.pushsdk.PushManager;
|
import com.vivo.push.IPushActionListener;
|
import com.vivo.push.PushClient;
|
import com.xiaomi.mipush.sdk.MiPushClient;
|
import com.yeshi.push.entity.PushApps;
|
import com.yeshi.push.entity.PushRomType;
|
|
public class PushUtil {
|
|
static String TAG = "PushUtil";
|
|
/**
|
* 推送 注册
|
*/
|
public static void inintPush(Application context, PushApps apps, ITokenListener tokenListener) {
|
if (context != null) {
|
String xmRegId = null;
|
switch (Build.BRAND.toLowerCase()) {
|
case "huawei":
|
case "honor":
|
//华为是自动初始化
|
return;
|
case "oppo"://上面官方判断
|
/***OPPO官方判断方法*/
|
if (apps.getOppo() == null)
|
break;
|
HeytapPushManager.init(context, true);
|
if (HeytapPushManager.isSupportPush()) {
|
String appKey = apps.getOppo().getAppKey();
|
String appSecret = apps.getOppo().getAppSecret();
|
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(PushRomType.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"://上面官方判断
|
if (apps.getVivo() == null)
|
break;
|
/***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(PushRomType.vivo, regId);
|
}
|
}
|
});
|
return;
|
}
|
break;
|
case "meizu"://魅族
|
|
{
|
if (apps.getMeizu() == null) {
|
break;
|
}
|
String appId = apps.getMeizu().getAppId();
|
String appKey = apps.getMeizu().getAppKey();
|
PushManager.register(context, appId, appKey);
|
return;
|
}
|
}
|
|
String appId = apps.getXm().getAppId();
|
String appKey = apps.getXm().getAppKey();
|
MiPushClient.registerPush(context, appId, appKey);//注册小米推送
|
xmRegId = MiPushClient.getRegId(context);
|
Log.i(TAG, "小米注册成功:" + xmRegId);
|
if (xmRegId != null && xmRegId.trim().length() > 0) {
|
tokenListener.onToken(PushRomType.xm, xmRegId);
|
}
|
|
}
|
}
|
|
|
public interface ITokenListener {
|
public void onToken(PushRomType romType, String regId);
|
}
|
|
}
|