improve permission check

This commit is contained in:
rca 2025-01-29 16:06:43 +09:00
parent f37932a037
commit 70ba6469a2

View File

@ -7,6 +7,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import androidx.core.app.ActivityCompat;
@ -91,15 +92,30 @@ public class bluetooth_setupFragment extends Fragment {
}
if (ActivityCompat.checkSelfPermission(requireActivity().getApplicationContext(), android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return view;
// if (ActivityCompat.checkSelfPermission(requireActivity().getApplicationContext(), android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// // TODO: Consider calling
// // ActivityCompat#requestPermissions
// // here to request the missing permissions, and then overriding
// // public void onRequestPermissionsResult(int requestCode, String[] permissions,
// // int[] grantResults)
// // to handle the case where the user grants the permission. See the documentation
// // for ActivityCompat#requestPermissions for more details.
// return view;
// }
// >= Android 12
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
if (ActivityCompat.checkSelfPermission(requireActivity().getApplicationContext(), android.Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
Log.w("Bluetooth", "Permission not granted(Android 12-)");
} else {
Log.w("Bluetooth", "Permission granted(Android 12-)");
}
} else {
if (ActivityCompat.checkSelfPermission(requireActivity().getApplicationContext(), android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
Log.w("Bluetooth", "Permission not granted(Android 12+)");
} else {
Log.w("Bluetooth", "Permission granted(Android 12+)");
}
}
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();