Skip to content

Commit 8d08ddb

Browse files
Settings for Tablets and Android 13 improved
Signed-off-by: Manfred Mueller <mail@manfred-mueller.org>
1 parent 39b14eb commit 8d08ddb

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

app/src/main/java/com/nass/ek/w3kiosk/SettingsActivity.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,24 @@ protected void onCreate(Bundle savedInstanceState) {
308308
}
309309

310310
c = findViewById(R.id.writeStorage);
311-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
312-
if (Environment.isExternalStorageManager()) {
313-
c.setChecked(true);
314-
c.setEnabled(false);
315-
} else {
316-
c.setChecked(false);
317-
c.setEnabled(true);
318-
}
311+
312+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
313+
// Android 11+ (API 30 and above, including Android 13)
314+
if (Environment.isExternalStorageManager()) {
315+
// If MANAGE_EXTERNAL_STORAGE permission is granted, disable the checkbox
316+
c.setChecked(true);
317+
c.setEnabled(false);
319318
} else {
320-
c.setChecked(context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
321-
c.setEnabled(context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED);
319+
// If not granted, enable checkbox to request permission
320+
c.setChecked(false);
321+
c.setEnabled(true);
322322
}
323+
} else {
324+
// Android 10 and below: Check WRITE_EXTERNAL_STORAGE permission
325+
boolean hasWritePermission = context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
326+
c.setChecked(hasWritePermission);
327+
c.setEnabled(!hasWritePermission);
328+
}
323329
String configFileContent = readConfigFileContents();
324330

325331
if (configFileContent.isEmpty()) {
@@ -512,20 +518,43 @@ public void checkOverlayPermission(View v){
512518
}
513519
}
514520

515-
public void checkStoragePermission(View v){
516-
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
517-
if (! Environment.isExternalStorageManager()) {
521+
public void checkStoragePermission(View v) {
522+
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
523+
// Android 13+ (API 33): Request permissions for media access
524+
if (!Environment.isExternalStorageManager()) {
525+
// Request MANAGE_EXTERNAL_STORAGE permission if not granted
518526
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
519527
Uri uri = Uri.fromParts("package", getPackageName(), null);
520528
intent.setData(uri);
521-
context.startActivity(intent);
529+
startActivityForResult(intent, 4710); // Start activity to manage permission
530+
} else {
531+
// If MANAGE_EXTERNAL_STORAGE is already granted, request media access permissions
532+
ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{
533+
Manifest.permission.READ_MEDIA_IMAGES,
534+
Manifest.permission.READ_MEDIA_VIDEO
535+
}, 4710);
536+
}
537+
} else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
538+
// Android 11+ (API 30): Request MANAGE_EXTERNAL_STORAGE permission
539+
if (!Environment.isExternalStorageManager()) {
540+
try {
541+
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
542+
Uri uri = Uri.fromParts("package", getPackageName(), null);
543+
intent.setData(uri);
544+
startActivityForResult(intent, 4710); // Start activity to manage permission
545+
} catch (Exception e) {
546+
e.printStackTrace();
547+
}
548+
} else {
549+
// If MANAGE_EXTERNAL_STORAGE is granted, no need for further permissions
522550
}
523551
} else {
524-
ActivityCompat.requestPermissions(SettingsActivity.this,new String[]{
525-
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4710);
552+
// Android 10 and below: Request WRITE_EXTERNAL_STORAGE permission
553+
ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{
554+
Manifest.permission.WRITE_EXTERNAL_STORAGE
555+
}, 4710);
526556
}
527557
}
528-
529558
public void checkWritePermission(View v){
530559
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
531560
if (! Settings.System.canWrite(this))

app/src/main/res/layout/activity_settings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@
338338
android:cursorVisible="true"
339339
android:gravity="bottom"
340340
android:inputType="text"
341-
android:enabled="true"
342341
android:maxLines="1"
343342
android:ellipsize="end"
344343
android:singleLine="true"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ configurations.configureEach {
1717
}
1818

1919
ext {
20-
verCode = 52
20+
verCode = 53
2121
verName = "2.6.3"
2222
releaseDir = file("${projectDir}/app/release")
2323
}

w3kiosk.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"versionCode":52,
2+
"versionCode":53,
33
"versionName":"2.6.3",
44
"contentText":"Neue W3Kiosk-Version",
55
"minSupport":1,

0 commit comments

Comments
 (0)