liuxue
2021-07-29 7e2df20ccc7cdfb528d309369460a4f3d66afdf1
Project/qk_sdk/src/main/java/com/secondworld/universalsdk/MainActivity.java
@@ -12,6 +12,7 @@
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;
@@ -82,7 +83,27 @@
        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
@@ -117,7 +138,7 @@
            // 申请成功
            QuickPlatformUtil.getInstance().onCreate();
            if (!QuickPlatformUtil.getInstance().isInited) {
                Sdk.getInstance().init(this, "88049844578484520615487574815873", "82414864");
                Sdk.getInstance().init(this, "96065423134516611008224414549989", "69623854");
            }
        } else {
            // 失败 这里逻辑以游戏为准 这里只是模拟申请失败 退出游戏 cp方可改为继续申请 或者其他逻辑
@@ -140,7 +161,7 @@
                        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() {
@@ -148,7 +169,7 @@
                    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");
                    }
                });
                // 显示
@@ -197,48 +218,48 @@
        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
@@ -275,7 +296,8 @@
        {
            if(QuickSDK.getInstance().isShowExitDialog()){
                Sdk.getInstance().exit(this);
            }else{
            }
            else{
                // 游戏调用自身的退出对话框,点击确定后,调用quick的exit接口
                new AlertDialog.Builder(MainActivity.this).setTitle("退出").setMessage("是否退出游戏?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
@@ -287,4 +309,6 @@
        }
        return super.onKeyDown(i, keyEvent);
    }
}