Fixed crash if no bluetooth adapter available to get device name

This commit is contained in:
Sylvain Berfini 2019-12-20 09:15:41 +01:00
parent 0525386363
commit 076ceff33e
2 changed files with 10 additions and 2 deletions

View file

@ -48,7 +48,10 @@ class ApiTwentySixPlus {
Settings.Global.getString(
context.getContentResolver(), Settings.Global.DEVICE_NAME);
if (name == null) {
name = BluetoothAdapter.getDefaultAdapter().getName();
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
name = adapter.getName();
}
}
if (name == null) {
name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name");

View file

@ -51,7 +51,12 @@ public class Compatibility {
return ApiTwentySixPlus.getDeviceName(context);
}
String name = BluetoothAdapter.getDefaultAdapter().getName();
String name = null;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
name = adapter.getName();
}
if (name == null) {
name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name");
}