|
@@ -2,6 +2,8 @@ package org.cocos2dx.javascript.application;
|
|
|
|
|
|
import android.app.Application;
|
|
|
import android.content.Context;
|
|
|
+import android.content.pm.ApplicationInfo;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
|
|
|
|
|
|
import com.umeng.commonsdk.UMConfigure;
|
|
@@ -10,6 +12,10 @@ import com.umeng.message.PushAgent;
|
|
|
import com.umeng.message.api.UPushRegisterCallback;
|
|
|
import com.xiaomi.mipush.sdk.PushMessageHelper;
|
|
|
|
|
|
+import org.android.agoo.huawei.HuaWeiRegister;
|
|
|
+import org.android.agoo.oppo.OppoRegister;
|
|
|
+import org.android.agoo.vivo.VivoRegister;
|
|
|
+import org.android.agoo.xiaomi.MiPushRegistar;
|
|
|
import org.cocos2dx.javascript.util.Consts;
|
|
|
import org.cocos2dx.javascript.util.CrashHandler;
|
|
|
import org.cocos2dx.javascript.util.Logger;
|
|
@@ -20,7 +26,7 @@ public class EApplication extends Application {
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
- Consts.mApplicatonContext = getApplicationContext();
|
|
|
+ Consts.mApplicatonContext = this;
|
|
|
UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "dfc59afd6dc6b1550ff1c2e0c7eb10fd");
|
|
|
UMConfigure.setLogEnabled(true);
|
|
|
// MediaPlayerManager.getDefault().init(Consts.mApplicatonContext, getPackageName());
|
|
@@ -38,18 +44,58 @@ public class EApplication extends Application {
|
|
|
//若不是主进程(":channel"结尾的进程),直接初始化sdk,不可在子线程中执行
|
|
|
PushHelper.init(getApplicationContext());
|
|
|
}
|
|
|
+ PushAgent.getInstance(getApplicationContext()).onAppStart();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void attachBaseContext(Context base) {
|
|
|
super.attachBaseContext(base);
|
|
|
}
|
|
|
+
|
|
|
+ public static String getChannelName() {
|
|
|
+ String code = "";
|
|
|
+ try {
|
|
|
+ PackageManager packageManager = Consts.mApplicatonContext.getPackageManager();
|
|
|
+ if (packageManager != null) {
|
|
|
+ //注意此处为ApplicationInfo 而不是 ActivityInfo,因为友盟设置的meta-data是在application标签中,而不是某activity标签中,所以用ApplicationInfo
|
|
|
+ ApplicationInfo applicationInfo = packageManager.
|
|
|
+ getApplicationInfo(Consts.mApplicatonContext.getPackageName(), PackageManager.GET_META_DATA);
|
|
|
+ if (applicationInfo != null) {
|
|
|
+ if (applicationInfo.metaData != null) {
|
|
|
+ code = String.valueOf(applicationInfo.metaData.get("UMENG_CHANNEL"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
class PushHelper {
|
|
|
+
|
|
|
+
|
|
|
public static void init(Context context) {
|
|
|
//获取消息推送实例
|
|
|
PushAgent pushAgent = PushAgent.getInstance(context);
|
|
|
+
|
|
|
+ String channelCode = EApplication.getChannelName();
|
|
|
+ if (channelCode.equals("2008")) {
|
|
|
+ //小米渠道
|
|
|
+ MiPushRegistar.register(context, "2882303761517510194", "r+ETScCARNYoaRwNV/BySw==", false);
|
|
|
+ } else if (channelCode.equals("2005")) {
|
|
|
+ //华为渠道
|
|
|
+ HuaWeiRegister.register(Consts.mApplicatonContext);
|
|
|
+ } else if (channelCode.equals("2007")) {
|
|
|
+ //vivo渠道
|
|
|
+ VivoRegister.register(context);
|
|
|
+ } else if (channelCode.equals("2004")) {
|
|
|
+ OppoRegister.register(context, "Dzb55KTW1gOoG8g408wSkwW08", "72cBB2D18C33571241C002748b964e3F");
|
|
|
+ }
|
|
|
+
|
|
|
//注册推送服务,每次调用register方法都会回调该接口
|
|
|
pushAgent.register(new UPushRegisterCallback() {
|
|
|
|