0

I want to get information whether the device is connected via bluetooth and send message if it's not. First of all I get the set of paired devices. And if the device name is 'AAA' or 'AA.A', connects the device. If device is connected, it has no problem, but if device isn't connected, it just attempts to connect and over after a while.

How can I get state whether device is connected or not connected (not check sending bluetooth state signal) And if device is not connected, how can I toast a message?

Here is a sample code:

for(BluetoothDevice device : pairDevices){
                //get name and address of paired devices
                Log.d("TEST", device.getName().toString() +" Device Is Connected!");
                Log.d("TEST", device.getAddress().toString() +" Device Is Connected!");
                if (device.getName() != null && device.getName().length() > 4) {
                    Log.d("Bluetooth Name: ", device.getName());
                    Log.d("Bluetooth Mac Address: ", device.getAddress());
                    mac_address = device.getAddress();
                    try {
//If device's name is 'AAA' or 'AA.A', connects that device
                            if (device.getName().substring(0, 3).equals("AAA") || device.getName().substring(0, 4).equals("BB.B")) {
                                this.registerReceiver(mReceiver, filter);//device connects if catch device connecting signal
                                presenter.connectBt(device);
                                return true;
                            }
                    }
                    catch ()
                    {
                        Toast.makeText(getApplicationContext(), "Try to new connect", Toast.LENGTH_SHORT).show();
                    }
                }

0 Answers0