All Files Access

pull/405/head
Mike 2025-01-31 18:37:28 -08:00
rodzic f609690123
commit 775a3824a8
3 zmienionych plików z 38 dodań i 0 usunięć

Wyświetl plik

@ -354,6 +354,9 @@
<string name="p_mapfile_choose">Choose map file</string>
<string name="mapfile_error">Error loading map file %s!</string>
<string name="p_all_files_access_title">Grant Storage Permissions</string>
<string name="p_all_files_access_summary">Tap to manage permissions for all files access.</string>
<string name="p_themefile">Theme file name</string>
<string name="p_themefile_summary">MapsForge rendering theme (XML)</string>
<string name="p_themefile_choose">Choose theme file</string>

Wyświetl plik

@ -224,6 +224,11 @@
android:title="@string/p_themefile"
android:summary="@string/p_themefile_summary" />
<Preference
android:key="all_files_access"
android:title="@string/p_all_files_access_title"
android:summary="@string/p_all_files_access_summary" />
</PreferenceCategory>
</PreferenceScreen>

Wyświetl plik

@ -12,6 +12,7 @@ import _root_.android.widget.Toast
import java.text.SimpleDateFormat
import java.io.{File, PrintWriter}
import java.util.Date
import android.provider.Settings
import org.json.JSONObject
@ -50,6 +51,16 @@ class PrefsAct extends PreferenceActivity {
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.preferences)
// Set the click listener for the "Manage All Files Access" preference
val allFilesAccessPref = findPreference("all_files_access")
if (allFilesAccessPref != null) {
allFilesAccessPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
def onPreferenceClick(preference: Preference) = {
openAllFilesAccessSettings() // Call the method to handle the access settings
true // Return true to indicate the click was handled
}
})
}
fileChooserPreference("mapfile", 123456, R.string.p_mapfile_choose)
fileChooserPreference("themefile", 123457, R.string.p_themefile_choose)
}
@ -157,4 +168,23 @@ class PrefsAct extends PreferenceActivity {
case _ => super.onOptionsItemSelected(mi)
}
}
def openAllFilesAccessSettings(): Unit = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// For Android 13+ (API 33 and above): open All Files Access settings
val intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.setData(Uri.parse("package:" + getPackageName()))
startActivity(intent)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// For Android 11 (API 30) and above but below Android 13, open App Info page directly
val intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.setData(Uri.parse("package:" + getPackageName()))
startActivity(intent)
} else {
// For older versions (Android 10 and below), open the App Info page
val intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.setData(Uri.parse("package:" + getPackageName()))
startActivity(intent)
}
}
}