@@ -54,21 +54,20 @@ public class AndroidLauncher extends AndroidApplication {
54
54
if (Build.VERSION.SDK_INT >= 23) {
55
55
if (checkSelfPermission(
56
56
Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
57
- Log.v (TAG, "Permission is granted but .obb was not found.");
57
+ Log.e (TAG, "Permission is granted but .obb was not found.");
58
58
// TODO Download .obb
59
59
exit();
60
60
} else {
61
61
Log.v(TAG, "Permission is revoked, requesting...");
62
+ bladeEngine.setWaitingForPermissions(true);
62
63
ActivityCompat.requestPermissions(AndroidLauncher.this,
63
64
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 2);
64
65
}
65
66
} else { // permission is automatically granted on sdk<23 upon installation
66
- Log.v (TAG, "Permission is granted in Manifest (sdk<23) but .obb was not found.");
67
+ Log.e (TAG, "Permission is granted in Manifest (sdk<23) but .obb was not found.");
67
68
// TODO Download .obb
68
69
exit();
69
70
}
70
- } else {
71
- bladeEngine.createWithExpansion();
72
71
}
73
72
}
74
73
}
@@ -85,15 +84,13 @@ public class AndroidLauncher extends AndroidApplication {
85
84
boolean success = ((AndroidFiles) Gdx.files).setAPKExpansion(BuildConfig.EXPANSION_FILE_VERSION, 0);
86
85
87
86
if (!success) {
88
- Log.v (TAG, "Permission accepted but .obb was not found.");
87
+ Log.e (TAG, "Permission accepted but .obb was not found.");
89
88
90
89
// TODO Download .obb
91
90
exit();
92
- } else {
93
- bladeEngine.createWithExpansion();
94
- }
91
+ }
95
92
} else {
96
- Log.v (TAG, "Permission denied by user.");
93
+ Log.e (TAG, "Permission denied by user.");
97
94
exit();
98
95
}
99
96
break;
@@ -112,17 +109,40 @@ public class AndroidLauncher extends AndroidApplication {
112
109
}
113
110
114
111
class AndroidEngine extends BladeEngine {
112
+ private boolean waitingForPermissions = false;
113
+
115
114
@Override
116
115
public void create() {
117
- if (BuildConfig.EXPANSION_FILE_VERSION == 0) {
118
- super.create();
116
+ if(waitingForPermissions)
117
+ return;
118
+
119
+ if (BuildConfig.EXPANSION_FILE_VERSION > 0) {
120
+ boolean success = ((AndroidFiles) Gdx.files).setAPKExpansion(BuildConfig.EXPANSION_FILE_VERSION, 0);
121
+
122
+ if(!success) {
123
+ Log.e(TAG, "Can not set APK expansion.");
124
+ Gdx.app.exit();
125
+ } else {
126
+ Log.d(TAG, "Expansion file stablish successfully!");
127
+ }
119
128
}
129
+
130
+ super.create();
120
131
}
121
132
122
- public void createWithExpansion() {
123
- ((AndroidFiles) Gdx.files).setAPKExpansion(BuildConfig.EXPANSION_FILE_VERSION, 0);
133
+ @Override
134
+ public void resume() {
135
+ if(waitingForPermissions) {
136
+ // returns from querying permissions
137
+ bladeEngine.setWaitingForPermissions(false);
138
+ bladeEngine.create();
139
+ }
140
+
141
+ super.resume();
142
+ }
124
143
125
- super.create();
144
+ public void setWaitingForPermissions(boolean v) {
145
+ waitingForPermissions = v;
126
146
}
127
147
}
128
148
}
0 commit comments