Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7774237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:19:38+00:00 2026-06-01T17:19:38+00:00

I would like to develop an application for sending a message to multiple devices

  • 0

I would like to develop an application for sending a message to multiple devices through blue tooth.I know blue tooth is a point to point communication even though i would like to connect and send a message as following steps:

1.Get the list of paired devices

2.Select a device from paired list

3.Connect to paired device , send a message to selected paired device

4.Disconnect from device

5.Get connection to another device and so on (one after another).

I am getting paired devices addresses list as follows:

       mBtAdapter = BluetoothAdapter.getDefaultAdapter();

      Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();


    if (pairedDevices.size() > 0) {
     for (BluetoothDevice device : pairedDevices) {

        pairedList.add(device.getAddress());

        }

     Log.v("11111111", "11111111111"+dev);
    }

I am trying to connect to them and sending a message when user clicks on a button as follows:

      ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {


        String message = "Haiii";

        for(int i=0;i<dev.size();i++){
            Log.v("device", "111111  :  "+pairedList.get(i));
        mbService.connect(mBtAdapter.getRemoteDevice(pairedList.get(i)));

                    mbService.write(message.getBytes());

                    mbService.stop();
        }




    }
}); 

From the above code i am getting connection when loop pairedList.get(0).But the message is not sending to another device.In another device api sample application has installed.

If I use pairedList.get(i) it is not connecting to any devices even single device also.

please help me .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:19:39+00:00Added an answer on June 1, 2026 at 5:19 pm

    try to create separate threads for each connection – I had a similar issue and creating a new thread for each connection solved it nicely. By the way I even create a new thread to establish the connection – so establishing the connection does not block the UI. Got this from the BT sample code…

    to create a new thread to establish a connection:

        mConnectBluetoothThread = new ConnectBluetoothThread(device);
        mConnectBluetoothThread.start();
    

    where ConnectBluetoothThread is defined like:

    public ConnectBluetoothThread(BluetoothDevice device) {
            if (DEBUG)
            Log.i(this.getClass().getSimpleName(),
                this.getClass().getName()
                    + " ->"
                    + Thread.currentThread().getStackTrace()[2]
                        .getMethodName());
    
            mmDevice = device;
            BluetoothSocket tmp = null;
    
            // Get a BluetoothSocket for a connection with the
            // given BluetoothDevice
            try {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
            } catch (IOException e) {
            Log.e(this.getClass().getSimpleName(), "create() failed", e);
            }
            mmSocket = tmp;
        }
    
        public void run() {
            if (DEBUG)
            Log.i(this.getClass().getSimpleName(),
                this.getClass().getName()
                    + " ->"
                    + Thread.currentThread().getStackTrace()[2]
                        .getMethodName());
            // TODO
            setName("ConnectThread");
    
            // Always cancel discovery because it will slow down a connection
            mBluetoothAdapter.cancelDiscovery();
    
            // Make a connection to the BluetoothSocket
            try {
            // This is a blocking call and will only return on a
            // successful connection or an exception
            mmSocket.connect();
            } catch (IOException e) {
    
            connectionFailed();
    
            // Close the socket
            try {
                mmSocket.close();
            } catch (IOException e2) {
                Log.e(this.getClass().getSimpleName(),
                    "unable to close() socket during connection failure",
                    e2);
            }
    
            return;
            }
    
            // Reset the ConnectThread because we're done
            synchronized (InterBT.this) {
            mConnectBluetoothThread = null;
            }
    
            // Start the connected thread
            connected(mmSocket, mmDevice);
        }
    
        public void cancel() {
            try {
            mmSocket.close();
            } catch (IOException e) {
            Log.e(this.getClass().getSimpleName(),
                "close() of connect socket failed", e);
            }
        }
        }
    
        public synchronized void connected(BluetoothSocket socket,
            BluetoothDevice device) {
        if (DEBUG)
            Log.d(this.getClass().getSimpleName(), "connected");
    
        // Cancel the thread that completed the connection
        if (mConnectBluetoothThread != null) {
            mConnectBluetoothThread.cancel();
            mConnectBluetoothThread = null;
        }
    
        // Cancel any thread currently running a connection
        if (mConnectedBluetoothThread != null) {
            mConnectedBluetoothThread.cancel();
            mConnectedBluetoothThread = null;
        }
    
        // Cancel the accept thread because we only want to connect to one
        // device
        // if (mAcceptThread != null) {mAcceptThread.cancel(); mAcceptThread =
        // null;}
    
        // Start the thread to manage the connection and perform transmissions
        mConnectedBluetoothThread = new ConnectionThreadBT(socket);
        mConnectedBluetoothThread.start();
    
        setState(STATE_CONNECTED);
    
        }
    

    and also create a new class ConnectionThreadBT that handles the connection to read and write:

    public class ConnectionThreadBT extends ConnectionThreadBase {
        private static final boolean DEBUG = true;
    
        private final BluetoothSocket mmSocket;
        private final InputStream mmInStream;
        private final OutputStream mmOutStream;
        byte[] responseBuffer = new byte[4096 * 4]; 
        int responseBufferLen = 0;
    
    
        public ConnectionThreadBT(BluetoothSocket socket) {
        if (DEBUG)
            Log.i(this.getClass().getSimpleName(),
                this.getClass().getName()
                    + " ->"
                    + Thread.currentThread().getStackTrace()[2]
                        .getMethodName());
    
        mmSocket = socket;
        InputStream tmpIn = null;
        OutputStream tmpOut = null;
    
        // Get the BluetoothSocket input and output streams
        try {
            tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
        } catch (IOException e) {
            Log.e(this.getClass().getSimpleName(), "temp sockets not created",
                e);
        }
    
        mmInStream = tmpIn;
        mmOutStream = tmpOut;
       }
    
        public void run() {
        if (DEBUG)
            Log.i(this.getClass().getSimpleName(),
                this.getClass().getName()
                    + " ->"
                    + Thread.currentThread().getStackTrace()[2]
                        .getMethodName());
        //we have successfully connected to BT
    
        //now inform UI 
    
        Home_Screen.sendMessageToHomeScreen(
            Home_Screen.MESSAGE_INTERBT_CONNECTION_TESTED,
            Home_Screen.CONNECTION_SUCCESS, true);
      }
    

    and then to write just call this method which is also defined within ConnectionThreadBT

    public void sendMsg(MyBuffer buffer){
            try {
            mmOutStream.write(buffer);
            mmOutStream.flush();
            successfullyWritten = true;
            } catch (IOException e) {
            Log.e(this.getClass().getSimpleName(),
                "Exception during write", e);
            successfullyWritten = false;
            }
    

    to read either do the same or start a monitoring loop in the run method which keeps reading as long as the connectedThread is alive and reports back any read information through a handler similar to the UI screen update

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to know if i can develop a OpenSocial based application for
I would like to develop a custom application (multiple screens, complex processes) on top
I would like to develop an iOS application that send files between other devices
I would like to develop Mono application for Win/Linux/Mac in C# on Windows. Is
I would like to develop a mobile application that is able to access all
I would like to develop an Android application which will have a local database.
As described in the title I would like to develop a Windows Forms Application
I need to develop a classic asp application on vista, and would like to
I would like to develop a small notifications application for Windows in .NET that
I would like to develop a cross platform application, i'm not sure which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.