permission integration in settings successful
package org.openbot.main;
import android.Manifest;
+import android.app.Activity;
+import android.content.Intent;
import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Bundle;
+import android.provider.Settings;
import android.view.View;
import android.widget.Toast;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
-import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreferenceCompat;
-import org.jetbrains.annotations.NotNull;
import org.openbot.R;
import org.openbot.env.Vehicle;
import org.openbot.utils.Constants;
@@ -80,6 +81,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
{
camera.setChecked(PermissionUtils.hasPermission(requireContext(), Manifest.permission.CAMERA));
camera.setOnPreferenceChangeListener((preference, newValue) -> {
+ if (camera.isChecked())
+ startInstalledAppDetailsActivity(requireActivity());
+ else
PermissionUtils.requestPermissions(
SettingsFragment.this,
new String[] {Constants.PERMISSION_CAMERA},
@@ -94,6 +98,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
{
storage.setChecked(PermissionUtils.hasPermission(requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE));
storage.setOnPreferenceChangeListener((preference, newValue) -> {
+ if (storage.isChecked())
+ startInstalledAppDetailsActivity(requireActivity());
+ else
PermissionUtils.requestPermissions(
SettingsFragment.this,
new String[]{Constants.PERMISSION_STORAGE},
@@ -109,6 +116,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
{
location.setChecked(PermissionUtils.hasPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION));
location.setOnPreferenceChangeListener((preference, newValue) -> {
+ if (location.isChecked())
+ startInstalledAppDetailsActivity(requireActivity());
+ else
PermissionUtils.requestPermissions(
SettingsFragment.this,
new String[] {Constants.PERMISSION_LOCATION},
@@ -124,6 +134,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
{
mic.setChecked(PermissionUtils.hasPermission(requireContext(), Manifest.permission.RECORD_AUDIO));
mic.setOnPreferenceChangeListener((preference, newValue) -> {
+ if (mic.isChecked())
+ startInstalledAppDetailsActivity(requireActivity());
+ else
PermissionUtils.requestPermissions(
SettingsFragment.this,
new String[] {Constants.PERMISSION_AUDIO_RECORDING},
@@ -217,5 +230,18 @@ public class SettingsFragment extends PreferenceFragmentCompat {
}
}
+ public void startInstalledAppDetailsActivity(final Activity context) {
+ if (context == null) {
+ return;
+ }
+ final Intent i = new Intent();
+ i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+ i.addCategory(Intent.CATEGORY_DEFAULT);
+ i.setData(Uri.parse("package:" + context.getPackageName()));
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+ context.startActivity(i);
+ }
}
