add more checks for possible NPE and simplify the UI
This commit is contained in:
parent
cc6b2736ce
commit
c399a17369
@ -17,7 +17,7 @@ public class BluetoothClient {
|
||||
}
|
||||
|
||||
public BluetoothConnection openConnection() throws IOException {
|
||||
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(BluetoothConstants.fdroidUuid());
|
||||
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(BluetoothConstants.fdroidUuid());
|
||||
BluetoothConnection connection = new BluetoothConnection(socket);
|
||||
connection.open();
|
||||
return connection;
|
||||
|
@ -31,6 +31,7 @@ import org.fdroid.fdroid.localrepo.SwapManager;
|
||||
import org.fdroid.fdroid.net.BluetoothDownloader;
|
||||
import org.fdroid.fdroid.net.bluetooth.BluetoothClient;
|
||||
import org.fdroid.fdroid.net.bluetooth.BluetoothConnection;
|
||||
import org.fdroid.fdroid.net.bluetooth.BluetoothServer;
|
||||
import org.fdroid.fdroid.views.fragments.ThemeableListFragment;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -134,13 +135,15 @@ public class BluetoothDeviceListView extends ListView implements
|
||||
|
||||
final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
final TextView deviceName = (TextView)headerView.findViewById(R.id.device_name);
|
||||
final TextView deviceName = (TextView) headerView.findViewById(R.id.device_name);
|
||||
deviceName.setText(bluetooth.getName());
|
||||
|
||||
final TextView address = (TextView)headerView.findViewById(R.id.device_address);
|
||||
final TextView address = (TextView) headerView.findViewById(R.id.device_address);
|
||||
address.setText(bluetooth.getAddress());
|
||||
|
||||
populateBondedDevices();
|
||||
initiateBluetoothScan();
|
||||
|
||||
// populateBondedDevices();
|
||||
|
||||
}
|
||||
|
||||
@ -166,8 +169,10 @@ public class BluetoothDeviceListView extends ListView implements
|
||||
{
|
||||
Log.d(TAG, "Starting bluetooth scan...");
|
||||
|
||||
if (cancelMenuItem != null) {
|
||||
cancelMenuItem.setVisible(true);
|
||||
scanMenuItem.setVisible(false);
|
||||
}
|
||||
|
||||
final ContentLoadingProgressBar loadingBar = getLoadingIndicator();
|
||||
|
||||
@ -181,8 +186,11 @@ public class BluetoothDeviceListView extends ListView implements
|
||||
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
Log.d(TAG, "Found bluetooth device: " + device.toString());
|
||||
|
||||
if (device != null && device.getName() != null)
|
||||
if (device.getName().contains(BluetoothServer.BLUETOOTH_NAME_TAG)) {
|
||||
boolean exists = false;
|
||||
for (int i = 0; i < adapter.getCount(); i ++) {
|
||||
for (int i = 0; i < adapter.getCount(); i++) {
|
||||
if (adapter.getItem(i).getAddress().equals(device.getAddress())) {
|
||||
exists = true;
|
||||
break;
|
||||
@ -194,6 +202,7 @@ public class BluetoothDeviceListView extends ListView implements
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final BroadcastReceiver scanCompleteReceiver = new BroadcastReceiver() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user