diff --git a/Android/app/build.gradle b/Android/app/build.gradle
index eb2d4b5bd..228cc3c0b 100644
--- a/Android/app/build.gradle
+++ b/Android/app/build.gradle
@@ -10,7 +10,7 @@ else {
android {
ndkVersion "26.0.10792818"
namespace 'com.dishii.soh'
- compileSdkVersion 31
+ compileSdkVersion 33
buildFeatures {
buildConfig = true
}
diff --git a/Android/app/src/main/AndroidManifest.xml b/Android/app/src/main/AndroidManifest.xml
index 0d3b724b0..d8691a0fd 100644
--- a/Android/app/src/main/AndroidManifest.xml
+++ b/Android/app/src/main/AndroidManifest.xml
@@ -73,6 +73,7 @@
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true"
+ android:requestLegacyExternalStorage="true"
android:appCategory="game" >
@@ -83,7 +84,7 @@
- = Build.VERSION_CODES.R) {
// Android 11+ → MANAGE_EXTERNAL_STORAGE
if (!Environment.isExternalStorageManager()) {
- Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
- intent.setData(Uri.parse("package:" + getPackageName()));
- startActivityForResult(intent, STORAGE_PERMISSION_REQUEST_CODE);
+ try {
+ Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
+ intent.setData(Uri.parse("package:" + getPackageName()));
+ startActivityForResult(intent, STORAGE_PERMISSION_REQUEST_CODE);
+ } catch (ActivityNotFoundException e) {
+ Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
+ startActivityForResult(intent, STORAGE_PERMISSION_REQUEST_CODE);
+ }
} else {
// Already granted
- checkAndSetupFiles();
+ if (isSetupStarted.compareAndSet(false, true)) {
+ doVersionCheck();
+ checkAndSetupFiles();
+ }
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Android 6–10 → request READ/WRITE at runtime
@@ -169,7 +193,10 @@ private void requestStoragePermission() {
STORAGE_PERMISSION_REQUEST_CODE);
} else {
// Below Android 6 → permissions granted at install time
- checkAndSetupFiles();
+ if (isSetupStarted.compareAndSet(false, true)) {
+ doVersionCheck();
+ checkAndSetupFiles();
+ }
}
}
@@ -326,7 +353,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Handle MANAGE_EXTERNAL_STORAGE result
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
- checkAndSetupFiles();
+ if (isSetupStarted.compareAndSet(false, true)) {
+ doVersionCheck();
+ checkAndSetupFiles();
+ }
} else {
Toast.makeText(this, "Storage permission is required to access files.", Toast.LENGTH_LONG).show();
}
@@ -334,6 +364,28 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
+ boolean allGranted = grantResults.length > 0;
+ for (int result : grantResults) {
+ if (result != PackageManager.PERMISSION_GRANTED) {
+ allGranted = false;
+ break;
+ }
+ }
+ if (allGranted) {
+ if (isSetupStarted.compareAndSet(false, true)) {
+ doVersionCheck();
+ checkAndSetupFiles();
+ }
+ } else {
+ Toast.makeText(this, "Storage permission is required to access files.", Toast.LENGTH_LONG).show();
+ }
+ }
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+
public void openFilePicker() {
// Create an Intent to open the file picker dialog
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);