try to return false if bluetoothAdapter is null otherwise return the output of isEnabled()
public static boolean isBlueToothEnabled(){
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(bluetoothAdapter == null){
return false;
}
return bluetoothAdapter.isEnabled();
}
Read more:
In Clean Code, Robert Martin writes, “Negatives are just a bit harder
to understand than positives. So, when possible, conditionals should
be expressed as positives.” (Martin, [G29]). IntelliJ IDEA has three
inspections to help you stay positive.
https://blog.jetbrains.com/idea/2014/09/the-inspection-connection-issue-2/
(Entry #4 Avoiding negative Conditionals)
https://www.jetbrains.com/help/idea/2016.1/invert-boolean.html