handle null adapter case

This commit is contained in:
n8fr8 2015-07-13 14:40:11 -04:00
parent b0b285bc1f
commit 99a86c4080

View File

@ -296,7 +296,8 @@ public class SwapWorkflowActivity extends ActionBarActivity {
Log.d(TAG, "Initiating Bluetooth swap instead of wifi."); Log.d(TAG, "Initiating Bluetooth swap instead of wifi.");
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
// TODO: May be null (e.g. on an emulator).
if (adapter != null)
if (adapter.isEnabled()) { if (adapter.isEnabled()) {
Log.d(TAG, "Bluetooth enabled, will pair with device."); Log.d(TAG, "Bluetooth enabled, will pair with device.");
ensureBluetoothDiscoverable(); ensureBluetoothDiscoverable();
@ -318,10 +319,11 @@ public class SwapWorkflowActivity extends ActionBarActivity {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivityForResult(intent, REQUEST_BLUETOOTH_DISCOVERABLE); startActivityForResult(intent, REQUEST_BLUETOOTH_DISCOVERABLE);
} else {
Log.d(TAG, "Bluetooth is already discoverable, so lets start the Bluetooth server.");
startBluetoothServer();
} }
Log.d(TAG, "Staring the Bluetooth Server whether we are discoverable or not, since paired devices can still connect.");
startBluetoothServer();
} }
private void startBluetoothServer() { private void startBluetoothServer() {