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

  • Home
  • SEARCH
  • 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 6694595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:07:12+00:00 2026-05-26T06:07:12+00:00

I’m designin an application in Android that connects the mobile to a bluetooth device.

  • 0

I’m designin an application in Android that connects the mobile to a bluetooth device. I can do this, as I open a BluetoothSocket like this:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
socket.connect();

Where device is the paired device with the mobile bluetooth desired. The thing is, this external device is a bit special, and it has different times for writing and answering to the mobile, so I need to put some timeouts on my socket for reading and writing, but I’ve searched a lot and it seems like BluetoothSocket doesn’t support this.

Can anybody tell me a different way to admin timeouts on reading and writing to the port on the BluetoothSocket class for Android?

Thank you!

  • 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-05-26T06:07:13+00:00Added an answer on May 26, 2026 at 6:07 am

    Here is the code for reading and writing code:

    Writng code on port:

    try
    {
        // Enviamos los bytes
        DataOutputStream dOut = null;
        dOut = new DataOutputStream(socket.getOutputStream());
        // Send message
        dOut.writeBytes(res);
        dOut.flush();
    }
    catch (IOException e)
    {
        Dialogs.showErrorDialog("Error al recuperar la fecha y hora del dispositivo Nonin.", this);
    }
    

    Then, reading from port until response available:

    DataInputStream dIn = null;
    // We receive the answer
    try
    {
         dIn = new DataInputStream(socket.getInputStream());
    }
    catch (IOException e)
    {
        Dialogs.showAlertDialog("An exception occured during bluetooth io stream creation", this);
    }
    
    while (true)
    {
        try
        {
             String data = dIn.readLine(); // readLine();
             byte[] total = EncodingUtils.getBytes(data, "ASCII");
             Dialogs.showInfoDialog("Mensaje ok: " + data.toString(), this);
        }
        catch (IOException e)
        {
              break;
         }
    }
    

    The thing is that I think the writing works, as I convert the desired string into bytes, and it works. But then, when I’m waiting for response, it mixes further responses with the desired, and I think this is because timings.

    There’s no more code in the middle related with sockets. First, I create it. Then, I try to send a byte String. Then I wait until I receive the answer for the byte String that I just sent.

    Thank you in advance.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have some data like this: 1 2 3 4 5 9 2 6
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,

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.