client_Hale
2018-09-04 fff1f19a381e6ad295cb3e7bd41cce48e74fbeea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.secondworld.univeralsdk;
 
import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Process;
import android.provider.Settings;
import android.support.v4.content.PermissionChecker;
import android.view.View;
import android.widget.FrameLayout;
 
import com.unity3d.player.UnityPlayerActivity;
 
public class MainActivity extends UnityPlayerActivity
{
    private static final String TAG = "MainActivity";
    public static boolean isForeground = false;
    // 启用6.0以上权限回调code
    // private static final int CODE_REQUEST_PERMISSION = 1000;
 
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
 
        LogUtil.i(TAG, "onCreate");
        LogUtil.init(this, true);
 
        setContentView(R.layout.activity_main);
 
        FrameLayout _frameLayout = (FrameLayout) findViewById(R.id.unity_view);
        View unityView = mUnityPlayer.getView();
        _frameLayout.addView(unityView);
 
        H2EngineSDK.onCreate(this, savedInstanceState);
    }
 
    @Override
    protected void onNewIntent(Intent intent)
    {
        super.onNewIntent(intent);
        H2EngineSDK.onNewIntent(this, intent);
        LogUtil.i(TAG, "onNewIntent");
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        H2EngineSDK.onActivityResult(requestCode, resultCode, data, this);
        super.onActivityResult(requestCode, resultCode, data);
    }
 
    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        H2EngineSDK.onConfigurationChanged(newConfig);
 
        super.onConfigurationChanged(newConfig);
        LogUtil.i(TAG, "onConfigurationChanged");
    }
 
    @Override
    protected void onStart()
    {
        H2EngineSDK.onStart(this);
 
        super.onStart();
        LogUtil.i(TAG, "onStart");
    }
 
    @Override
    protected void onStop()
    {
        isForeground = false;
        H2EngineSDK.onStop(this);
 
        super.onStop();
        LogUtil.i(TAG, "onStop");
    }
 
    @Override
    protected void onResume()
    {
        isForeground = true;
        H2EngineSDK.onResume(this);
 
        super.onResume();
        LogUtil.i(TAG, "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();
        }
    }
 
    @Override
    protected void onPause()
    {
        H2EngineSDK.onPause(this);
 
        super.onPause();
        LogUtil.i(TAG, "onPause");
    }
 
    @Override
    protected void onDestroy()
    {
        H2EngineSDK.onDestroy(this);
 
        super.onDestroy();
        LogUtil.i(TAG, "onDestroy");
    }
 
    @Override
    protected void onRestart()
    {
        H2EngineSDK.onRestart(this);
 
        super.onRestart();
        LogUtil.i(TAG, "onRestart");
    }
 
}