| | |
| | | import android.provider.Settings; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.v4.app.ActivityCompat; |
| | | import android.support.v4.content.ContextCompat; |
| | | import android.support.v4.content.PermissionChecker; |
| | | import android.util.Log; |
| | | import android.view.KeyEvent; |
| | |
| | | View unityView = mUnityPlayer.getView(); |
| | | _frameLayout.addView(unityView); |
| | | |
| | | H2EngineSDK.onCreate(this, savedInstanceState); |
| | | //H2EngineSDK.onCreate(this, savedInstanceState); |
| | | |
| | | Sdk.getInstance().onCreate(this); |
| | | try { |
| | | // check权限 |
| | | if ((ContextCompat.checkSelfPermission(this, |
| | | Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) |
| | | || (ContextCompat.checkSelfPermission(this, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) { |
| | | // 没有 , 申请权限 权限数组 |
| | | ActivityCompat.requestPermissions(this, new String[] { |
| | | Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); |
| | | } else { |
| | | QuickPlatformUtil.getInstance().onCreate(); |
| | | Sdk.getInstance().init(this,"96065423134516611008224414549989", "69623854"); |
| | | } |
| | | } catch (Exception e) { |
| | | QuickPlatformUtil.getInstance().onCreate(); |
| | | Sdk.getInstance().init(this, "96065423134516611008224414549989", "69623854"); |
| | | } |
| | | QuickSDK.getInstance().setIsLandScape(true); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 申请成功 |
| | | QuickPlatformUtil.getInstance().onCreate(); |
| | | if (!QuickPlatformUtil.getInstance().isInited) { |
| | | Sdk.getInstance().init(this, "88049844578484520615487574815873", "82414864"); |
| | | Sdk.getInstance().init(this, "96065423134516611008224414549989", "69623854"); |
| | | } |
| | | } else { |
| | | // 失败 这里逻辑以游戏为准 这里只是模拟申请失败 退出游戏 cp方可改为继续申请 或者其他逻辑 |
| | |
| | | intent.setData(uri); |
| | | startActivityForResult(intent, REQUEST_RECORD_PERMISSION_SETTING); |
| | | QuickPlatformUtil.getInstance().onCreate(); |
| | | Sdk.getInstance().init(UnityPlayer.currentActivity, "88049844578484520615487574815873", "82414864"); |
| | | Sdk.getInstance().init(UnityPlayer.currentActivity, "96065423134516611008224414549989", "69623854"); |
| | | } |
| | | }); |
| | | normalDialog.setNegativeButton("关闭", new DialogInterface.OnClickListener() { |
| | |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | Toast.makeText(UnityPlayer.currentActivity, "权限被拒绝", Toast.LENGTH_SHORT).show(); |
| | | QuickPlatformUtil.getInstance().onCreate(); |
| | | Sdk.getInstance().init(UnityPlayer.currentActivity, "88049844578484520615487574815873", "82414864"); |
| | | Sdk.getInstance().init(UnityPlayer.currentActivity, "96065423134516611008224414549989", "69623854"); |
| | | } |
| | | }); |
| | | // 显示 |
| | |
| | | super.onResume(); |
| | | |
| | | // 检测本地存储权限是否有, 没有的话要提示用户 |
| | | if (PermissionChecker.checkPermission(this, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| | | Process.myPid(), Process.myUid(), |
| | | getPackageName()) != PackageManager.PERMISSION_GRANTED |
| | | || PermissionChecker.checkPermission(this, |
| | | Manifest.permission.READ_EXTERNAL_STORAGE, |
| | | Process.myPid(), Process.myUid(), |
| | | getPackageName()) != PackageManager.PERMISSION_GRANTED) |
| | | { |
| | | new AlertDialog.Builder(this) |
| | | .setMessage("应用没有存储读取权限,点击确定至设置中开启,否则无法继续游戏.") |
| | | .setCancelable(false) |
| | | .setPositiveButton("确定", |
| | | new DialogInterface.OnClickListener() |
| | | { |
| | | @Override |
| | | public void onClick(DialogInterface dialogInterface, |
| | | int i) |
| | | { |
| | | UniversalUtil.hasGoToSetting = true; |
| | | Intent intent = new Intent( |
| | | Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | Uri uri = Uri.fromParts("package", |
| | | getPackageName(), |
| | | null); |
| | | intent.setData(uri); |
| | | startActivity(intent); |
| | | } |
| | | }) |
| | | .setNegativeButton("拒绝", |
| | | new DialogInterface.OnClickListener() |
| | | { |
| | | @Override |
| | | public void onClick(DialogInterface dialogInterface, |
| | | int i) |
| | | { |
| | | finish(); |
| | | } |
| | | }) |
| | | .show(); |
| | | } |
| | | // if (PermissionChecker.checkPermission(this, |
| | | // Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| | | // Process.myPid(), Process.myUid(), |
| | | // getPackageName()) != PackageManager.PERMISSION_GRANTED |
| | | // || PermissionChecker.checkPermission(this, |
| | | // Manifest.permission.READ_EXTERNAL_STORAGE, |
| | | // Process.myPid(), Process.myUid(), |
| | | // getPackageName()) != PackageManager.PERMISSION_GRANTED) |
| | | // { |
| | | // new AlertDialog.Builder(this) |
| | | // .setMessage("应用没有存储读取权限,点击确定至设置中开启,否则无法继续游戏.") |
| | | // .setCancelable(false) |
| | | // .setPositiveButton("确定", |
| | | // new DialogInterface.OnClickListener() |
| | | // { |
| | | // @Override |
| | | // public void onClick(DialogInterface dialogInterface, |
| | | // int i) |
| | | // { |
| | | // UniversalUtil.hasGoToSetting = true; |
| | | // Intent intent = new Intent( |
| | | // Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| | | // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | // Uri uri = Uri.fromParts("package", |
| | | // getPackageName(), |
| | | // null); |
| | | // intent.setData(uri); |
| | | // startActivity(intent); |
| | | // } |
| | | // }) |
| | | // .setNegativeButton("拒绝", |
| | | // new DialogInterface.OnClickListener() |
| | | // { |
| | | // @Override |
| | | // public void onClick(DialogInterface dialogInterface, |
| | | // int i) |
| | | // { |
| | | // finish(); |
| | | // } |
| | | // }) |
| | | // .show(); |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | |
| | | { |
| | | if(QuickSDK.getInstance().isShowExitDialog()){ |
| | | Sdk.getInstance().exit(this); |
| | | }else{ |
| | | } |
| | | else{ |
| | | // 游戏调用自身的退出对话框,点击确定后,调用quick的exit接口 |
| | | new AlertDialog.Builder(MainActivity.this).setTitle("退出").setMessage("是否退出游戏?").setPositiveButton("确定", new DialogInterface.OnClickListener() { |
| | | @Override |
| | |
| | | } |
| | | return super.onKeyDown(i, keyEvent); |
| | | } |
| | | |
| | | |
| | | } |