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 6252377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:47:27+00:00 2026-05-24T13:47:27+00:00

I have written a program that constantly reads from the Bluetooth via SPP and

  • 0

I have written a program that constantly reads from the Bluetooth via SPP and prints the contents in the stream to a edittext box. I have the following thread:

myTimer = new Timer();
myTimer.schedule(new TimerTask(){
   @Override
   public void run(){
     TimerMethod();
   }
},0,1000);

private void TimerMethod(){this.runOnUiThread(startReading);}


private Runnable startReading = new Runnable(){

    public void run(){
        EditText _txtArea = (EditText) findViewById(R.id._txtArea);
    try{
        inStream = btSocket.getInputStream();
    }catch (IOException e3) {
        _txtArea.append("inStream establishment Failed!");

    }

Now the msg’s incoming can be of any size and I want to keep reading until there isn’t anything remaining to be read. I tried an implementation where i did something like this:

   byte[] msgIn = new byte[15];
   inStream.read(msgIn, 0, 15);
            int len = msgIn.length;
            for (int i=0; i<len; i++){
                out = new Character ((char) msgIn[i]).toString();       
                _txtArea.append(out);

But that limits the read to 15 bytes and the code doesn’t seem very effecient. If anyone is wondering why i have the following line out = new Character ((char) msgIn[i]).toString(); it’s because the data coming in is in ASCII i am converting it to a char. Also using this method after reading all of the contents when there is nothing else to read the program hangs. Does anyone know a way i can keep reading until all of the data has been read?

  • 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-24T13:47:28+00:00Added an answer on May 24, 2026 at 1:47 pm

    I figured it out, for those who are interested it is because the stream should be closed before a read so that inputStream.read() will be able to reach -1 after all data has been sent

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

Sidebar

Related Questions

I have written a program that reads in a File object (really an XML
I have written a program that invokes a system command from inside: #include <stdlib.h>
I have written a program that prints a table. I have not included the
I have written a program that takes the filename from argv[1] and do operations
I have written a program that will etablish a network connection with a remote
I have a website cgi-bin program that is written in c++. Unfortunately the website
I have a console program written in C# that I am using to send
I have a bash script that runs a simulation program written in Fortran 90,
I have a program that loads a file (anywhere from 10MB to 5GB) a
I have written a program that handles signal for Floating point exception and I

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.