| | |
| | | public String channelID; |
| | | int REQUEST_RECORD_PERMISSION_SETTING = 110; |
| | | |
| | | private boolean hasPermissions(Activity activity) { |
| | | 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); |
| | | |
| | | return 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.WRITE_EXTERNAL_STORAGE}, RequestCode.QUICK); |
| | | // } else { |
| | | // QuickSdkMgr.I.register(PlatformDiff.I.platformProductCode(), PlatformDiff.I.platformProductKey()); |
| | | // QuickSdkMgr.I.init(activity); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // //QuickSdkMgr.I.init(activity); |
| | | // ActivityCompat.requestPermissions(activity, new String[]{ |
| | | // Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCode.QUICK); |
| | | // } |
| | | // ActivityCompat.requestPermissions(activity, new String[]{ |
| | | // Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCode.QUICK); |
| | | |
| | | try { |
| | | QuickSdkMgr.I.register(PlatformDiff.I.platformProductCode(), PlatformDiff.I.platformProductKey()); |
| | | QuickSdkMgr.I.init(activity); |
| | | if (!hasPermissions(activity)) { |
| | | 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) { |
| | | 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)) { |
| | | // //申请成功 |
| | | // QuickSdkMgr.I.register(PlatformDiff.I.platformProductCode(), PlatformDiff.I.platformProductKey()); |
| | | // QuickSdkMgr.I.init(activity); |
| | | // 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("SdkManager", "onActivityResult"); |
| | | LogUtil.i("unity-sdk", "onActivityResult"); |
| | | requestPermissions(activity); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | public void init(Activity activity) { |
| | | sdkInitState = SdkInitState.LOADING; |
| | |
| | | LogUtil.debug("SdkManager", "初始化成功"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String message, String trace) { |
| | | //初始化失败 |
| | |
| | | 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 |