Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

<application android:label="@string/app_name" android:icon="@drawable/icon"
android:name=".APRSdroidApplication"
Expand Down
3 changes: 3 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
43 changes: 42 additions & 1 deletion src/PrefsAct.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -113,8 +124,19 @@ class PrefsAct extends PreferenceActivity {
//parseFilePickerResult(data, "mapfile", R.string.mapfile_error)
val takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
getContentResolver.takePersistableUriPermission(data.getData(), takeFlags)
val resolvedPath = data.getData().getScheme match {
case "file" => data.getData().getPath
case "content" => resolveContentUri(data.getData())
case _ => null
}

if (resolvedPath != null) {
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putString("mapfile", data.getDataString()).commit()
.edit().putString("mapfile", resolvedPath).commit()
Toast.makeText(this, resolvedPath, Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, R.string.mapfile_error, Toast.LENGTH_SHORT).show()
}
finish()
startActivity(getIntent())
} else
Expand Down Expand Up @@ -146,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)
}
}
}