From c9132d7d97e22571e3896b5ff0c9ac13385c556a Mon Sep 17 00:00:00 2001 From: m2049r Date: Tue, 5 Nov 2024 08:42:14 +0100 Subject: [PATCH] more permission checks --- .../xmrwallet/SidekickConnectFragment.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java b/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java index 4310195a..e787e32d 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java @@ -76,12 +76,13 @@ public class SidekickConnectFragment extends Fragment @Override public void onPause() { Timber.d("onPause()"); - if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) - throw new IllegalStateException("Bluetooth permission not granted"); - if (bluetoothAdapter.isDiscovering()) { - bluetoothAdapter.cancelDiscovery(); + if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) { + Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show(); + } else { + if (bluetoothAdapter.isDiscovering()) { + bluetoothAdapter.cancelDiscovery(); + } } - // the the activity we are connected? why? it can ask the bluetoothservice... super.onPause(); } @@ -161,8 +162,10 @@ public class SidekickConnectFragment extends Fragment // Make sure we're not doing discovery anymore if (bluetoothAdapter != null) { - if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) - throw new IllegalStateException("Bluetooth permission not granted"); + if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) { + Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show(); + return; + } bluetoothAdapter.cancelDiscovery(); } }