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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:59:02+00:00 2026-05-23T01:59:02+00:00

I have a fairly simple program based largely on a simple bluetooth test client

  • 0

I have a fairly simple program based largely on a simple bluetooth test client application posted here:

http://www.anddev.org/code-snippets-for-android-f33/serial-over-bluetooth-simple-test-client-t11106.html

My application has 4 buttons, each button sending a different byte of data over the bluetooth connection.

It seems to work just fine for a few seconds. The connection is made, the RFCOMM socket connects and for the first few seconds data is sent over the over the connection (and recieved at the other side)
After a few seconds of perfection, however, the data stops getting through. Then no matter which of the 4 buttons I press nothing happens.

Then when I press the “Exit” button (which attempts to close the bluetooth socket using the .close() function) suddenly all the data that had not been getting through suddenly goes through all at once (as if it was being stored up in a buffer) immediatly before the connection is closed. and the recieving device goes back into discovery mode.

I do not understand why the connection drops, and starts storing the data up, any Ideas?

Thanks,
James

Target: Galaxy Tab @ Android 2.3.3
Recieving Device: TI EZ430-RF2560 eval kit

    package com.launcher.LaunchControl;

import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;


import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class ThinBTClient extends Activity implements OnClickListener {

        private static final String TAG = "THINBTCLIENT";
        public static final String ADDRESS = "ADDRESS";
        private static final boolean D = true;
        private BluetoothAdapter mBluetoothAdapter = null;
        private BluetoothSocket btSocket = null;
        private OutputStream outStream = null;
        byte [] msgBuffer = {0x01, 0x02, 0x03, 0x04};

        private static final UUID MY_UUID =         //Bluetooth UUID to resolve to SSP Port 1 ^^
                        UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

        private static String address;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.mainlaunch);

                findViewById(R.id.ExitButton).setOnClickListener(this);
                findViewById(R.id.LaunchButton1).setOnClickListener(this);
                findViewById(R.id.LaunchButton2).setOnClickListener(this);
                findViewById(R.id.LaunchButton3).setOnClickListener(this);
                findViewById(R.id.LaunchButton4).setOnClickListener(this);

                if (D)
                        Log.e(TAG, "+++ ON CREATE +++");

                mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
                if (mBluetoothAdapter == null) {
                        Toast.makeText(this,
                                "Bluetooth is not available.",
                                Toast.LENGTH_LONG).show();
                        finish();
                        return;
                }

                if (!mBluetoothAdapter.isEnabled()) {
                        Toast.makeText(this,
                                "Please enable your BT and re-run this program.",
                                Toast.LENGTH_LONG).show();
                        finish();
                        return;
                }

                if (D)
                        Log.e(TAG, "+++ DONE IN ON CREATE, GOT LOCAL BT ADAPTER +++");

                Bundle extras = getIntent().getExtras();
                if(extras !=null) {
                    if (extras.getString(ADDRESS) != null){;
                    address = extras.getString(ADDRESS);
                    }
                }
        }

        @Override
        public void onStart() {
                super.onStart();
                if (D)
                        Log.e(TAG, "++ ON START ++");
        }

        @Override
        public void onResume() {
                super.onResume();

                if (D) {
                        Log.e(TAG, "+ ON RESUME +");                                             
                        Log.e(TAG, "+ ABOUT TO ATTEMPT CLIENT CONNECT +");
                }

                BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

                try {
                        btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
                } catch (IOException e) {
                        Log.e(TAG, "ON RESUME: Socket creation failed.", e);
                }
                mBluetoothAdapter.cancelDiscovery();

                try {
                        btSocket.connect();
                        Log.e(TAG, "ON RESUME: BT connection established, data transfer link open.");
                } catch (IOException e) {
                        try {
                                btSocket.close();
                        } catch (IOException e2) {
                                Log.e(TAG,
                                        "ON RESUME: Unable to close socket during connection failure", e2);
                        }
                }                               
        }

        @Override
        public void onPause() {
                super.onPause();

                if (D)
                        Log.e(TAG, "- ON PAUSE -");

                if (outStream != null) {
                        try {
                                outStream.flush();
                        } catch (IOException e) {
                                Log.e(TAG, "ON PAUSE: Couldn't flush output stream.", e);
                        }
                }

                try     {
                        btSocket.close();
                } catch (IOException e2) {
                        Log.e(TAG, "ON PAUSE: Unable to close socket.", e2);
                }
        }

        @Override
        public void onStop() {
                super.onStop();
                if (D)
                        Log.e(TAG, "-- ON STOP --");
        }

        @Override
        public void onDestroy() {
                super.onDestroy();
                if (D)
                        Log.e(TAG, "--- ON DESTROY ---");
                try {
                    btSocket.close();
                } catch (IOException e1) {
                    Log.e(TAG, "ON RESUME: Unable to close socket during connection failure");
                }
        }

        @Override
        public void onClick(View v) {
            switch (v.getId())
            {
            case R.id.ExitButton:

                try {
                    btSocket.close();
                } catch (IOException e1) {
                    Log.e(TAG, "ON RESUME: Unable to close socket during connection failure");
                }
                this.finish();
                break;


            case R.id.LaunchButton1:             

                try {
                    outStream = btSocket.getOutputStream();
                    } 
                catch (IOException e) {
                    Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
                    }

                try {
                        outStream.write(msgBuffer[0]);
                } catch (IOException e) {
                        Log.e(TAG, "ON RESUME: Exception during write.", e);
                }   
                outStream = null;           
                break;


            case R.id.LaunchButton2:
                try {
                    outStream = btSocket.getOutputStream();
                    } 
                catch (IOException e) {
                    Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
                    }

                try {
                        outStream.write(msgBuffer[1]);
                } catch (IOException e) {
                        Log.e(TAG, "ON RESUME: Exception during write.", e);
                }   
                outStream = null;   
                break;          


            case R.id.LaunchButton3:
                try {
                    outStream = btSocket.getOutputStream();
                    } 
                catch (IOException e) {
                    Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
                    }

                try {
                        outStream.write(msgBuffer[2]);
                } catch (IOException e) {
                        Log.e(TAG, "ON RESUME: Exception during write.", e);
                }   
                outStream = null;   
                break;



            case R.id.LaunchButton4:
                try {
                    outStream = btSocket.getOutputStream();
                    } 
                catch (IOException e) {
                    Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
                    }

                try {
                        outStream.write(msgBuffer[3]);
                } catch (IOException e) {
                        Log.e(TAG, "ON RESUME: Exception during write.", e);
                }   
                outStream = null;   
                break;
            }

        }
}
  • 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-23T01:59:02+00:00Added an answer on May 23, 2026 at 1:59 am

    The Tab and (in my experience with 6 different devices) all Samsung devices have TERRIBLE Bluetooth SPP implementations. I’d suggest choosing a different device.

    Also, I would check that you are calling flush on the OutputStream, particularly if you are not sending line separators.

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

Sidebar

Related Questions

I have a fairly simple addition to the HTTP standard. An ambitious goal I
We have a fairly simple program that's used for creating backups. I'm attempting to
I have a fairly simple non-clustered application running ehcache with spring and hibernate. On
I have a fairly simple ASP.NET 2.0 menu control using a sitemap file and
I have a fairly simple const struct in some C code that simply holds
I have a fairly simple sync problem. I have a table with about 10
Let's say I have a fairly simple app that lets users store information on
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
We have fairly large C++ application which is composed of about 60 projects in
I've written a fairly simple java application that allows you to drag your mouse

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.