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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:13:50+00:00 2026-06-08T04:13:50+00:00

I am creating an Android application which connects my device to an embedded chip

  • 0

I am creating an Android application which connects my device to an embedded chip via Bluetooth. I am modeling my design after a program which already exists on the Palm Pilot( written in C ). I am using the Bluetooth Chat example to get my code running, and have gotten stuck. I am pretty new to the whole coding world still, and am confusing myself slightly.

I want to convert the following code from C to Java….

SrmReceive(portId,&c,1,(t*5L*Sec)/1000L,&err)

The only real problem I’m having here, is the third parameter. The 1 represents the number of bytes to receive, as stated in the palm docs, and is of type UInt32.

The code from the Bluetooth Chat example has the following function for reading in data…

            public void run() {
                Log.i( TAG, "BEGIN mConnectedThread" );
                buffer = new byte[1024];
                int bytes;

                // Keep listening to the InputStream while connected
                while( true ) {
                try {
                    // Read from the InputStream
                    bytes = mmInStream.read( buffer );

                    // Send the obtained bytes to the UI Activity
                    mHandler.obtainMessage( BtHelperHandler.MessageType.READ, bytes, buffer).sendToTarget();
                } catch ( IOException e ) {
                    Log.e( TAG, "disconnected", e );
                    sendErrorMessage( 1 );
                    break;
                }
            }
        }

I want to change the run() method to have a parameter for the certain number of bytes to read. I am slightly confused as to what to do. I was thinking…

public void run( int size ) {
    buffer = new byte[size];
    ...
}

But that doesn’t seem right to me, I feel like I’m mixing up my definition of byte. May sound stupid but I’m not confident with this information enough yet. It is confusing to me to convert a UInt32 to java, since java does not have an equivalent type. If anyone knows please let me know.

  • 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-08T04:13:51+00:00Added an answer on June 8, 2026 at 4:13 am

    No reason to be confused, what you’re doing is correct. Assuming mmInStream is an instance of InputStream;

    byte[] buffer = new byte[1024];
    int bytes = mmInStream.read(buffer);
    

    Will read whatever is available up to a maximum of 1024 bytes, and return however many bytes it read. This is a low level approach to data streams, which is fine, it just means that you have to know what to do with this byte array now that you have it.

    If you’re reading primitives a lot, you might want to take a look at DataInputStream, use it like so;

    DataInputStream dat = new DataInputStream(mmInStream);
    int x = dat.readInt();
    

    Will read 32 bits of data (4 bytes) from your stream, and line them up into a java int primitive. Things to watch out for, are endianness, and signed/unsigned conflation. If you run into problems, reading off bytes into a 32 bit int is achieved using the << operator, adding each byte in turn, then left-shifting by 8 bits.

    In your situation, what I would do is just take a look at the values in buffer after a read, and figure out what exactly is being sent, eyeballing the stream could be important because of the two reasons I give above.

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

Sidebar

Related Questions

I am creating an Android application which will have some embedded music inside of
I'm creating an android application which should parse a Json from a file or
I am creating an android application in which I am using table layout in
I am new to android development. I am creating an android application, in which
I have an Android Bluetooth application which manages a couple of remote devices( Capsules
I am creating an android application in which I have to insert an image
I'm creating an application for android which is a 3D inside navigation system of
i am creating an application which connects 4 devices. one of them acts as
I'm creating a Android application which uses a Switch . I'm trying to listen
I am developing an application in android in which i creating a list view

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.