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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:32:27+00:00 2026-06-15T12:32:27+00:00

I am trying to send accelerator values over bluetooth from an Android App to

  • 0

I am trying to send accelerator values over bluetooth from an Android App to the PC. I am working on the BluetoothChat demo application. In the Android App I have a method called onSensorChanged that will be called every time when the accelerations changes. the method looks like below:

@Override
public void onSensorChanged(SensorEvent e) {
    // the work done when the accelerometer data changes
    try {
        Thread.sleep(25);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
    sensorX = e.values[0];
    sensorY = e.values[1];

    Toast.makeText(BluetoothChat.this, "x coordinate = " + sensorX + "y coordinate = " + sensorY Toast.LENGTH_SHORT).show();

    BigDecimal sensorXDec = new BigDecimal(e.values[0]).setScale(2,BigDecimal.ROUND_HALF_UP);
    BigDecimal sensorYDec = new BigDecimal(e.values[1]).setScale(2,BigDecimal.ROUND_HALF_UP);


    String vals = String.valueOf(sensorXDec.toPlainString() + "," + sensorYDec.toPlainString()); 

    mChatService.writeFromString(vals);

}

The method writeFromString

    public void writeFromString(String temp){
    // Create temporary object
    ConnectedThread r;
    // Synchronize a copy of the ConnectedThread
    synchronized (this) {
        if (mState != STATE_CONNECTED) return;
        r = mConnectedThread;
    }
    // Perform the write unsynchronized
    r.writeString(temp);
}

and the writeString method is the following:

        public void writeString(String out) {
        try {
                if(D) Log.d(TAG, "Sending File....AS STRING");
                mmOutStream.write(out.getBytes(), 0, out.getBytes().length);

        } catch (IOException e) {
            Log.e(TAG, "Exception during write", e);
        }
    }

in the following method I process the inputStream on the PC side

    @Override
public void run() {
    try {
        // prepare to receive data
        InputStream inputStream = mConnection.openInputStream();

        System.out.println("waiting for input");

        while (true) {
            int command = inputStream.read();

            if (command == EXIT_CMD)
            {   
                System.out.println("finish process");
                break;
            }
            processCommand(command);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

The question again is: How can I retrieve each set of Strings I am sending from the Android App?

  • 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-15T12:32:29+00:00Added an answer on June 15, 2026 at 12:32 pm

    Try this

    String msg = null;
    BufferedReader br = new BufferedReader(
    new InputStreamReader(inputStream)
    );

    msg = br.readLine();

    This will solve problem

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

Sidebar

Related Questions

i'm trying to send/receive data over wifi to an iphone/ipodtouch app from a C#
Am trying to send a mail to recipient from iPhone app without user's interaction.
I'm trying to send a very basic XML string from a Windows Phone application
trying to send Arabic text from android to PHP file using the code below
Trying to send 3rd party scripts over an SSL or SPDY connection is a
Trying to send some email in my C# app. I am behind a proxy
Trying to send a complex type between two systems that have the same code
im trying to send rest api Users.getLoggedInUser i have all the secret session and
I am trying to send emails from smtps (secure smtp) using Indy and the
I am trying to send data as a model from an html form to

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.