1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| // LE RECEIVER QUI PERMET DE DECOUVRIR LES NOUVELLES DEVICES
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// SE LANCE QUAND UNE NOUVELLE DEVICE EST DETECTE
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
int doublon_present = 0 ;
String devi_name;
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.e("DECOUVERTE", device.getName());
BDevice devi = new BDevice(device.getName(), device.getAddress(), device);
devi_name = devi.get_BDevice_name();
for(int i=0; i<mAdapter.getCount(); i++) {
BDevice doublon = mAdapter.getItem(i);
String doublon_name = doublon.get_BDevice_name();
Log.d("DOUBLON FOR DEVI FOUND", doublon_name+ " " + devi_name);
if(Objects.equals(devi_name, doublon_name)){
doublon_present = 1;
}
Log.d("Valeur de l'int", String.valueOf(doublon_present));
}
if(doublon_present == 0){
mAdapter.add(devi);
}
}
}
};
// LORSQUE JE CLIQUE SUR UNE DES DEVICES
private AdapterView.OnItemClickListener mDeviceClickListener = new AdapterView.OnItemClickListener() {
BluetoothSocket socketsocket;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BluetoothDevice dev = deviceItemList.get(position).get_BDevice();
device_obd = dev;
DeviceSingleton.setDevice(device_obd);
// Service qui gère la connexion Bluetooth tourne mon petit coupaing
Intent intentzoo = new Intent(MainActivity.this, Service_connexion.class);
startService(intentzoo);
IntenSingleton.setService(intentzoo);
//On lance l'intent
Intent myIntent = new Intent(MainActivity.this, ManageOBD2.class);
myIntent.putExtra("oui", true);
socketsocket = SocketSingleton.getSocket();
MainActivity.this.startActivity(myIntent);
//thread_connexion.cancel();
}
}; |
Partager