androidmanifest.xml 权限声明
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
运行时动态权限获取
{
permissions.add(Manifest.permission.CAMERA);
permissions.add(Manifest.permission.BLUETOOTH);
permissions.add(Manifest.permission.BLUETOOTH_ADMIN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
permissions.add(Manifest.permission.BLUETOOTH_CONNECT);
permissions.add(Manifest.permission.BLUETOOTH_SCAN);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ) {
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
permissions.add(Manifest.permission.BLUETOOTH_CONNECT);
permissions.add(Manifest.permission.BLUETOOTH_SCAN);
}
}