From c909d4c38007492a422cdc8915889d583012af3c Mon Sep 17 00:00:00 2001 From: Sriharsha Singam Date: Wed, 9 Jan 2019 21:19:33 -0500 Subject: [PATCH] bluetooth no device duplication (fixes #139) (#140) --- .../remote/Fragments/RPIDialogFragment.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/treehouses/remote/Fragments/RPIDialogFragment.java b/app/src/main/java/io/treehouses/remote/Fragments/RPIDialogFragment.java index 44c46499b..b026b401f 100644 --- a/app/src/main/java/io/treehouses/remote/Fragments/RPIDialogFragment.java +++ b/app/src/main/java/io/treehouses/remote/Fragments/RPIDialogFragment.java @@ -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(); } @@ -110,6 +104,13 @@ public void onItemClick(AdapterView parent, View view, int position, long id) // listView.setAdapter(new ArrayAdapter(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; } @@ -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; } } @@ -203,9 +204,6 @@ public void onReceive(Context context, Intent intent) { s.add(deviceName+ "\n" + deviceHardwareAddress); listView.setAdapter(new ArrayAdapter(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)){