| | |
| | | |
| | | 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); |
| | | ActivityCompat.requestPermissions(activity, new String[]{ |
| | | Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCode.QUICK); |
| | | |
| | | } |
| | | 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)) { |
| | | |
| | | |
| | | //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.setPositiveButton("前往设置", new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| | | Uri uri = Uri.fromParts("package", activity.getPackageName(), null); |
| | | intent.setData(uri); |
| | | activity.startActivityForResult(intent, REQUEST_RECORD_PERMISSION_SETTING); |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | normalDialog.setNegativeButton("退出", new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | GameAppProxy.appExit(); |
| | | } |
| | | }); |
| | | // 显示 |
| | | normalDialog.show(); |
| | | // final AlertDialog.Builder normalDialog = new AlertDialog.Builder(activity); |
| | | // normalDialog.setTitle("权限设置"); |
| | | // normalDialog.setMessage("游戏需要部分权限才能正常运行,请前往设置中打开存储权限"); |
| | | // normalDialog.setPositiveButton("前往设置", new DialogInterface.OnClickListener() { |
| | | // @Override |
| | | // public void onClick(DialogInterface dialog, int which) { |
| | | // Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| | | // Uri uri = Uri.fromParts("package", activity.getPackageName(), null); |
| | | // intent.setData(uri); |
| | | // activity.startActivityForResult(intent, REQUEST_RECORD_PERMISSION_SETTING); |
| | | // dialog.dismiss(); |
| | | // } |
| | | // }); |
| | | // normalDialog.setNegativeButton("退出", new DialogInterface.OnClickListener() { |
| | | // @Override |
| | | // public void onClick(DialogInterface dialog, int which) { |
| | | // GameAppProxy.appExit(); |
| | | // } |
| | | // }); |
| | | // // 显示 |
| | | // normalDialog.show(); |
| | | } |
| | | |
| | | 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; |
| | |
| | | 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 |