From 500d52c89fcc2abe728d6a4b8d50889ab8a81f29 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 7 Jun 2020 16:47:24 +0200 Subject: [PATCH] Added button to go to Android app settings --- .../eu/faircode/email/FragmentOptionsMisc.java | 18 ++++++++++++++++++ .../main/res/layout/fragment_options_misc.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 344538e8db..ca3fa66fbc 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -28,7 +28,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Paint; +import android.net.Uri; import android.os.Bundle; +import android.provider.Settings; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -82,6 +84,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swCleanupAttachments; private Button btnCleanup; private TextView tvLastCleanup; + private Button btnApp; private Button btnMore; private TextView tvProcessors; @@ -137,6 +140,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swCleanupAttachments = view.findViewById(R.id.swCleanupAttachments); btnCleanup = view.findViewById(R.id.btnCleanup); tvLastCleanup = view.findViewById(R.id.tvLastCleanup); + btnApp = view.findViewById(R.id.btnApp); btnMore = view.findViewById(R.id.btnMore); tvProcessors = view.findViewById(R.id.tvProcessors); @@ -308,6 +312,20 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + final Intent app = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + app.setData(Uri.parse("package:" + getContext().getPackageName())); + btnApp.setEnabled(app.resolveActivity(getContext().getPackageManager()) != null); + btnApp.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + getContext().startActivity(app); + } catch (Throwable ex) { + ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, app.getAction()), Toast.LENGTH_LONG).show(); + } + } + }); + btnMore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 4b0a4c1c76..05d5019576 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -331,6 +331,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvCleanupHint" /> +