Skip to content

Commit

Permalink
bluetooth no device duplication (fixes #139) (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sriharsha-Singam authored and dogi committed Jan 10, 2019
1 parent 4cf2f28 commit c909d4c
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
});

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
getActivity().registerReceiver(mReceiver, filter);

if(mChatService == null){
setupBluetoothService();
}
Expand All @@ -110,6 +104,13 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
// listView.setAdapter(new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, s));
}
}

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
getActivity().registerReceiver(mReceiver, filter);

return mDialog;
}

Expand Down Expand Up @@ -194,7 +195,7 @@ public void onReceive(Context context, Intent intent) {
String deviceHardwareAddress = device.getAddress(); // MAC address
boolean alreadyExist = false;
for(BluetoothDevice checkDevices : devices){
if(checkDevices == device){
if(checkDevices.equals(device)){
alreadyExist = true;
}
}
Expand All @@ -203,9 +204,6 @@ public void onReceive(Context context, Intent intent) {
s.add(deviceName+ "\n" + deviceHardwareAddress);
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, s));
}
// if(deviceName!=null){
// }

Log.e("Broadcast BT", device.getName() + "\n" + device.getAddress());
}
else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
Expand Down

0 comments on commit c909d4c

Please sign in to comment.