|  |  |  | 
|---|
|  |  |  | private static final String TAG = "H2EngineSDK"; | 
|---|
|  |  |  | private static String APP_ID = ""; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static boolean PushEnable = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void HandleUnityMessage(String json) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LogUtil.i(TAG, "收到Unity发来的信息: " + json); | 
|---|
|  |  |  | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case CodeU2A.AssetCopy: | 
|---|
|  |  |  | FileUtil.copyAssets(_activity); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case CodeU2A.CopyOneAsset: | 
|---|
|  |  |  | FileUtil.copy(_activity,_json.getString("fileName")); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case CodeU2A.BatteryListenStart: | 
|---|
|  |  |  | BatteryUtil.getInstance().start(_activity); | 
|---|
|  |  |  | 
|---|
|  |  |  | case CodeU2A.FreePlatformSwitchAccount: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case CodeU2A.FreePlatformLogout: | 
|---|
|  |  |  | SpPlatformUtil.getInstance().logout(); | 
|---|
|  |  |  | SpPlatformUtil.getInstance().logout(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case CodeU2A.FreePlatformPay: | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | SpPlatformUtil.getInstance().pay(_activity, | 
|---|
|  |  |  | _json.getString("title"), | 
|---|
|  |  |  | _json.getString("cpInfo"), | 
|---|
|  |  |  | (float)_json.getDouble("mount"), | 
|---|
|  |  |  | (float) _json.getDouble("mount"), | 
|---|
|  |  |  | _extraData.toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | 
|---|
|  |  |  | SpPlatformUtil.getInstance().createRole(_json.getString("sid"), | 
|---|
|  |  |  | _json.getString("serverName"), | 
|---|
|  |  |  | _json.getString("roleID"), | 
|---|
|  |  |  | _json.getString("roleName").trim().replace(" ",""), | 
|---|
|  |  |  | _json.getString( | 
|---|
|  |  |  | "roleName").trim().replace(" ", | 
|---|
|  |  |  | ""), | 
|---|
|  |  |  | _json.getString("level"), | 
|---|
|  |  |  | _json.getString("familyName").trim().replace(" ",""), | 
|---|
|  |  |  | _json.getString( | 
|---|
|  |  |  | "familyName").trim().replace( | 
|---|
|  |  |  | " ", ""), | 
|---|
|  |  |  | _json.getString("gameName"), | 
|---|
|  |  |  | _json.getString("job"), | 
|---|
|  |  |  | _json.getString("vipLevel"), | 
|---|
|  |  |  | 
|---|
|  |  |  | SpPlatformUtil.getInstance().enterWorld(_json.getString("sid"), | 
|---|
|  |  |  | _json.getString("serverName"), | 
|---|
|  |  |  | _json.getString("roleID"), | 
|---|
|  |  |  | _json.getString("roleName").trim().replace(" ",""), | 
|---|
|  |  |  | _json.getString( | 
|---|
|  |  |  | "roleName").trim().replace(" ", | 
|---|
|  |  |  | ""), | 
|---|
|  |  |  | _json.getString("level"), | 
|---|
|  |  |  | _json.getString("familyName").trim().replace(" ",""), | 
|---|
|  |  |  | _json.getString( | 
|---|
|  |  |  | "familyName").trim().replace( | 
|---|
|  |  |  | " ", ""), | 
|---|
|  |  |  | _json.getString("gameName"), | 
|---|
|  |  |  | _json.getString("job"), | 
|---|
|  |  |  | _json.getString("vipLevel"), | 
|---|
|  |  |  | 
|---|
|  |  |  | SpPlatformUtil.getInstance().levelUp(_json.getString("sid"), | 
|---|
|  |  |  | _json.getString("serverName"), | 
|---|
|  |  |  | _json.getString("roleID"), | 
|---|
|  |  |  | _json.getString("roleName").trim().replace(" ",""), | 
|---|
|  |  |  | _json.getString("roleName").trim().replace( | 
|---|
|  |  |  | " ", ""), | 
|---|
|  |  |  | _json.getString("level"), | 
|---|
|  |  |  | _json.getString("familyName").trim().replace(" ",""), | 
|---|
|  |  |  | _json.getString( | 
|---|
|  |  |  | "familyName").trim().replace(" ", | 
|---|
|  |  |  | ""), | 
|---|
|  |  |  | _json.getString("gameName"), | 
|---|
|  |  |  | _json.getString("job"), | 
|---|
|  |  |  | _json.getString("vipLevel"), | 
|---|
|  |  |  | 
|---|
|  |  |  | case CodeU2A.JPushRemoveLocalMessage: | 
|---|
|  |  |  | removeNotification(_activity, _json.getInt("id")); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case CodeU2A.SendRegistEvent: | 
|---|
|  |  |  | SpPlatformUtil.getInstance().SendRegisterEvent(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (JSONException e) | 
|---|
|  |  |  | 
|---|
|  |  |  | public static void addLocalNotification(Activity activity, int id, String title, String content, | 
|---|
|  |  |  | long fireTime) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | if (PushEnable) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | JPushLocalNotification ln = new JPushLocalNotification(); | 
|---|
|  |  |  | ln.setBuilderId(0);// 设置样式 | 
|---|
|  |  |  | ln.setNotificationId(id);// id | 
|---|
|  |  |  | ln.setTitle(title);// 标题 | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | JPushLocalNotification ln = new JPushLocalNotification(); | 
|---|
|  |  |  | ln.setBuilderId(0);// 设置样式 | 
|---|
|  |  |  | ln.setNotificationId(id);// id | 
|---|
|  |  |  | ln.setTitle(title);// 标题 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ln.setContent(content);// 内容 | 
|---|
|  |  |  | ln.setBroadcastTime(fireTime);// 等待时间 | 
|---|
|  |  |  | JPushInterface.addLocalNotification(activity, ln); | 
|---|
|  |  |  | } catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | ln.setContent(content);// 内容 | 
|---|
|  |  |  | ln.setBroadcastTime(fireTime);// 等待时间 | 
|---|
|  |  |  | JPushInterface.addLocalNotification(activity, ln); | 
|---|
|  |  |  | } catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void removeNotification(Activity activity, int id) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | JPushInterface.removeLocalNotification(activity, id); | 
|---|
|  |  |  | if (PushEnable) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | JPushInterface.removeLocalNotification(activity, id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void GetExternalStorage() | 
|---|
|  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PushEnable = activity.getPackageName().equals("com.xjaz.sp"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | new Thread(new Runnable() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | UniversalUtil.sendMessageToUnity(_msgStruct); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // ------------------------------- 极光推送 ------------------------------- | 
|---|
|  |  |  | JPushInterface.setDebugMode(true); | 
|---|
|  |  |  | JPushInterface.init(activity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | final long _waitingTime = System.currentTimeMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | while (true) | 
|---|
|  |  |  | String _registrationID = "0"; | 
|---|
|  |  |  | if (PushEnable) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 等待获取极光registrationID | 
|---|
|  |  |  | if (!JPushInterface.getRegistrationID(activity).equals("")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | JPushInterface.setDebugMode(true); | 
|---|
|  |  |  | JPushInterface.init(activity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long _escapeTime = System.currentTimeMillis() - _waitingTime; | 
|---|
|  |  |  | final long _waitingTime = System.currentTimeMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (_escapeTime > 3000) | 
|---|
|  |  |  | while (true) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LogUtil.w(TAG, "等待获取极光推送registrationID超时: 3秒"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | // 等待获取极光registrationID | 
|---|
|  |  |  | if (!JPushInterface.getRegistrationID(activity).equals("")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _registrationID = JPushInterface.getRegistrationID(activity); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long _escapeTime = System.currentTimeMillis() - _waitingTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (_escapeTime > 3000) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | LogUtil.w(TAG, "等待获取极光推送registrationID超时: 3秒"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _msgStruct.clear(); | 
|---|
|  |  |  | _msgStruct.put("code", CodeA2U.PushClientID); | 
|---|
|  |  |  | _msgStruct.put("clientID", JPushInterface.getRegistrationID(activity)); | 
|---|
|  |  |  | _msgStruct.put("clientID", _registrationID); | 
|---|
|  |  |  | UniversalUtil.sendMessageToUnity(_msgStruct); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _msgStruct.clear(); | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SPGameController.getInstance().onResume(activity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(SpPlatformUtil.getInstance().payProcessing) | 
|---|
|  |  |  | if (SpPlatformUtil.getInstance().payProcessing) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Map<String, Object> _msgStruct = new HashMap<>(); | 
|---|
|  |  |  | _msgStruct.put("code", CodeA2U.FreePlatformPayCancel); | 
|---|