|  |  | 
 |  |  | import com.secondworld.sdk.utils.LogUtil; | 
 |  |  | import com.secondworld.sdk.utils.RequestCode; | 
 |  |  | import com.unity3d.player.UnityPlayer; | 
 |  |  | import com.secondworld.sdk.PlatformDiff; | 
 |  |  |  | 
 |  |  | import org.json.JSONException; | 
 |  |  | import org.json.JSONObject; | 
 |  |  | 
 |  |  |  | 
 |  |  |     String productCode; | 
 |  |  |     String productKey; | 
 |  |  |  | 
 |  |  |     public String channelID; | 
 |  |  |     int REQUEST_RECORD_PERMISSION_SETTING = 110; | 
 |  |  |  | 
 |  |  |     private boolean hasPermissions(Activity activity) { | 
 |  |  |         return (ContextCompat.checkSelfPermission(activity, | 
 |  |  |                 Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) | 
 |  |  |                 && (ContextCompat.checkSelfPermission(activity, | 
 |  |  |                 Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); | 
 |  |  |     public boolean hasPermissions(Activity activity) { | 
 |  |  |         //权限提取到各自项目中 | 
 |  |  | //        return (ContextCompat.checkSelfPermission(activity, | 
 |  |  | //                Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) | 
 |  |  | //                && (ContextCompat.checkSelfPermission(activity, | 
 |  |  | //                Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); | 
 |  |  |  | 
 |  |  |         String[] permissionStr = PlatformDiff.I.platformPermission(); | 
 |  |  |         for (int i = 0; i < permissionStr.length; i++) | 
 |  |  |         { | 
 |  |  |             if (ContextCompat.checkSelfPermission(activity, permissionStr[i]) != PackageManager.PERMISSION_GRANTED) | 
 |  |  |             { | 
 |  |  |                 return false; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void requestPermissions(Activity activity) { | 
 |  |  |  | 
 |  |  |         try { | 
 |  |  |             // check权限 | 
 |  |  |             if (!hasPermissions(activity)) { | 
 |  |  |                 // 没有则申请权限 | 
 |  |  |                 ActivityCompat.requestPermissions(activity, new String[]{ | 
 |  |  |                         Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCode.QUICK); | 
 |  |  |             } else { | 
 |  |  |                 ActivityCompat.requestPermissions(activity, PlatformDiff.I.platformPermission(), RequestCode.QUICK); | 
 |  |  |             } | 
 |  |  |             else | 
 |  |  |             { | 
 |  |  |                 QuickSdkMgr.I.register(PlatformDiff.I.platformProductCode(), PlatformDiff.I.platformProductKey()); | 
 |  |  |                 QuickSdkMgr.I.init(activity); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             QuickSdkMgr.I.init(activity); | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         catch (Exception e) { | 
 |  |  |             LogUtil.i("SdkManager", "requestPermissions 初始化SDK失败"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void onRequestPermissionsResult(Activity activity, int requestCode, int[] grantResults) { | 
 |  |  |     public void onRequestPermissionsResult(Activity activity, int requestCode, int[] grantResults, String[] permissions) { | 
 |  |  |         if (requestCode != RequestCode.QUICK) return; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         if (hasPermissions(activity)) { | 
 |  |  |             LogUtil.i("SdkManager", "onRequestPermissionsResult 申请成功"); | 
 |  |  |             //申请成功 | 
 |  |  |             QuickSdkMgr.I.register(PlatformDiff.I.platformProductCode(), PlatformDiff.I.platformProductKey()); | 
 |  |  |             QuickSdkMgr.I.init(activity); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         final AlertDialog.Builder normalDialog = new AlertDialog.Builder(activity); | 
 |  |  |         normalDialog.setTitle("权限设置"); | 
 |  |  |         normalDialog.setMessage("游戏需要部分权限才能正常运行,请前往设置中打开电话权限与存储权限"); | 
 |  |  |         normalDialog.setMessage("游戏需要部分权限才能正常运行,请前往设置中打开存储权限"); | 
 |  |  |         normalDialog.setPositiveButton("前往设置", new DialogInterface.OnClickListener() { | 
 |  |  |             @Override | 
 |  |  |             public void onClick(DialogInterface dialog, int which) { | 
 |  |  | 
 |  |  |  | 
 |  |  |     public void onActivityResult(Activity activity, int requestCode) { | 
 |  |  |         if (requestCode == REQUEST_RECORD_PERMISSION_SETTING) | 
 |  |  |         { | 
 |  |  |             LogUtil.i("unity-sdk", "onActivityResult"); | 
 |  |  |             requestPermissions(activity); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     public void init(Activity activity) { | 
 |  |  |         sdkInitState = SdkInitState.LOADING; | 
 |  |  | 
 |  |  |                 if (GameActivityProxy.I.activity == null) | 
 |  |  |                     return; | 
 |  |  |                 if (hasPermissions(GameActivityProxy.I.activity)) { | 
 |  |  |                     init(BtGameMain.I.activity); | 
 |  |  |                     Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); | 
 |  |  |                     //init(BtGameMain.I.activity); | 
 |  |  |                     Toast.makeText(GameAppProxy.app, "异常请重启游戏", Toast.LENGTH_LONG).show(); | 
 |  |  |                 } | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             case LOADING: { | 
 |  |  |                 Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); | 
 |  |  |                 Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等!", Toast.LENGTH_LONG).show(); | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |                 LogUtil.debug("SdkManager", "初始化成功"); | 
 |  |  |                 UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitOk); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             @Override | 
 |  |  |             public void onFailed(String message, String trace) { | 
 |  |  |                 //初始化失败 | 
 |  |  | 
 |  |  |                 try { | 
 |  |  |                     args.clear(); | 
 |  |  |                     JSONObject info = new JSONObject(); | 
 |  |  |                     String channel = com.quicksdk.Extend.getInstance().getExtrasConfig("channel"); | 
 |  |  |                     if (channel == null || channel.isEmpty()) | 
 |  |  |                         channel = com.quicksdk.Extend.getInstance().getChannelType() + ""; | 
 |  |  |                     String account = userInfo.getUID() + "@" + channel; | 
 |  |  |                     channelID = com.quicksdk.Extend.getInstance().getExtrasConfig("channel"); | 
 |  |  |                     if (channelID == null || channelID.isEmpty()) | 
 |  |  |                         channelID = com.quicksdk.Extend.getInstance().getChannelType() + ""; | 
 |  |  |                     String account = userInfo.getUID() + "@" + channelID; | 
 |  |  |                     info.put("account", account); | 
 |  |  |                     info.put("userName", userInfo.getUID()); | 
 |  |  |                     info.put("token", userInfo.getToken()); | 
 |  |  | 
 |  |  |                     e.printStackTrace(); | 
 |  |  |                     LogUtil.e("SdkManager 登录成功", e); | 
 |  |  |                 } | 
 |  |  |                 PlatformDiff.I.LoginSuccess(); | 
 |  |  |                 verifyRealName(); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  | 
 |  |  |             @Override | 
 |  |  |             public void onSuccess() { | 
 |  |  |                 //退出成功,游戏在此做自身的退出逻辑处理 | 
 |  |  |                 UnityMsgHandler.sendMessageToUnity(CodeA2U.ExitGame); | 
 |  |  |                 //UnityMsgHandler.sendMessageToUnity(CodeA2U.ExitGame); | 
 |  |  |                 if (GameActivityProxy.I.activity == null) | 
 |  |  |                 { | 
 |  |  |                     UnityMsgHandler.sendMessageToUnity(CodeA2U.ExitGame); | 
 |  |  |                     return; | 
 |  |  |                 } | 
 |  |  |                 LogUtil.i("SdkManager", "activity退出"); | 
 |  |  |                 GameActivityProxy.I.activity.finish(); | 
 |  |  |                 android.os.Process.killProcess(android.os.Process.myPid()); | 
 |  |  |                 System.exit(0); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             @Override |