@@ -54,21 +54,20 @@ public class AndroidLauncher extends AndroidApplication {
5454 if (Build.VERSION.SDK_INT >= 23) {
5555 if (checkSelfPermission(
5656 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.");
5858 // TODO Download .obb
5959 exit();
6060 } else {
6161 Log.v(TAG, "Permission is revoked, requesting...");
62+ bladeEngine.setWaitingForPermissions(true);
6263 ActivityCompat.requestPermissions(AndroidLauncher.this,
6364 new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 2);
6465 }
6566 } 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.");
6768 // TODO Download .obb
6869 exit();
6970 }
70- } else {
71- bladeEngine.createWithExpansion();
7271 }
7372 }
7473 }
@@ -85,15 +84,13 @@ public class AndroidLauncher extends AndroidApplication {
8584 boolean success = ((AndroidFiles) Gdx.files).setAPKExpansion(BuildConfig.EXPANSION_FILE_VERSION, 0);
8685
8786 if (!success) {
88- Log.v (TAG, "Permission accepted but .obb was not found.");
87+ Log.e (TAG, "Permission accepted but .obb was not found.");
8988
9089 // TODO Download .obb
9190 exit();
92- } else {
93- bladeEngine.createWithExpansion();
94- }
91+ }
9592 } else {
96- Log.v (TAG, "Permission denied by user.");
93+ Log.e (TAG, "Permission denied by user.");
9794 exit();
9895 }
9996 break;
@@ -112,17 +109,40 @@ public class AndroidLauncher extends AndroidApplication {
112109 }
113110
114111 class AndroidEngine extends BladeEngine {
112+ private boolean waitingForPermissions = false;
113+
115114 @Override
116115 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+ }
119128 }
129+
130+ super.create();
120131 }
121132
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+ }
124143
125- super.create();
144+ public void setWaitingForPermissions(boolean v) {
145+ waitingForPermissions = v;
126146 }
127147 }
128148}
0 commit comments