Android >= 12: Add link in preferences to enable opening links

This commit is contained in:
johan12345
2022-11-13 14:19:15 +01:00
parent 0ed82d15ff
commit 88ace5ba82
4 changed files with 33 additions and 0 deletions

View File

@@ -1,8 +1,13 @@
package net.vonforst.evmap.fragment.preference
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.preference.ListPreference
import androidx.preference.Preference
import net.vonforst.evmap.R
import net.vonforst.evmap.ui.getAppLocale
import net.vonforst.evmap.ui.updateAppLocale
@@ -20,6 +25,9 @@ class UiSettingsFragment : BaseSettingsFragment() {
updateAppLocale(newValue as String)
true
}
val appLinkPref = findPreference<Preference>("applink_associate")!!
appLinkPref.isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
}
override fun onResume() {
@@ -34,4 +42,21 @@ class UiSettingsFragment : BaseSettingsFragment() {
}
}
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key) {
"applink_associate" -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val context = context ?: return false
val intent = Intent(
Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS,
Uri.parse("package:${context.packageName}")
)
context.startActivity(intent)
}
return true
}
}
return super.onPreferenceTreeClick(preference)
}
}

View File

@@ -284,4 +284,6 @@
<string name="prediction_only">(nur %s)</string>
<string name="prediction_dc_plugs_only">DC-Anschlüsse</string>
<string name="data_source_switched_to">Datenquelle zu %s umgeschaltet</string>
<string name="pref_applink_associate">Unterstützte Links öffnen</string>
<string name="pref_applink_associate_summary">von goingelectric.de und openchargemap.org</string>
</resources>

View File

@@ -283,4 +283,6 @@
<string name="prediction_only">(%s only)</string>
<string name="prediction_dc_plugs_only">DC plugs</string>
<string name="data_source_switched_to">Data source switched to %s</string>
<string name="pref_applink_associate">Open supported links</string>
<string name="pref_applink_associate_summary">from goingelectric.de and openchargemap.org</string>
</resources>

View File

@@ -28,4 +28,8 @@
android:summaryOn="@string/pref_navigate_use_maps_on"
android:summaryOff="@string/pref_navigate_use_maps_off"
android:defaultValue="true" />
<Preference
android:key="applink_associate"
android:title="@string/pref_applink_associate"
android:summary="@string/pref_applink_associate_summary" />
</PreferenceScreen>