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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:54:56+00:00 2026-06-07T00:54:56+00:00

Iam trying to connect my android device with a bluetooth compatible device. I know

  • 0

Iam trying to connect my android device with a bluetooth compatible device. I know the mac-address of this device, as you can see in my code below. I also made several Toasts just to verify the steps in the code. It seems that I manage to create tmp = device.createRfcommSocketToServiceRecord(MY_UUID); I assume this because the Toast raises a message saying some bluetooth object address, in this line of code:

String test = tmp.toString(); 
Toast.makeText(getApplicationContext(), "The bluetooth socket: " +test, Toast.LENGTH_LONG).show(); 

But the code failes semantically when I do a tmp.connect(); I am working on API level 15, android 4.0

This i my piece of code

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;  
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.Button;
import android.widget.Toast;

public class SimpleConnectAndroidActivity extends Activity {

final static String toast = "IAM HERE"; 

final static String TAG ="SimpleConnect";
UUID MY_UUID;

BluetoothDevice bd;
BluetoothAdapter ba;

Button connectButton;

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

    MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

    ba = BluetoothAdapter.getDefaultAdapter();

    connectButton = (Button)findViewById(R.id.button1);
    connectButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            boolean b = ba.checkBluetoothAddress("00:1B:DC:0F:EC:7E");
            BluetoothSocket tmp = null; 

            //If valid bluetoothAddress
            if(b) {
                final BluetoothDevice device = ba.getRemoteDevice("00:1B:DC:0F:EC:7E"); //Getting the Verifier Bluetooth 

                //Trying to create a RFCOMM socket to the device
                try {
                    tmp = device.createRfcommSocketToServiceRecord(MY_UUID);

                } catch (IOException e) {

                }

                try {
                    tmp.connect();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "No connection was made! Exception: " + e.getMessage(), Toast.LENGTH_LONG).show();
                } 
                //Print out the sockets name
                String test = tmp.toString(); 
                Toast.makeText(getApplicationContext(), "The bluetooth socket: " +test, Toast.LENGTH_LONG).show(); 
            }


            else {
                    Toast.makeText(getApplicationContext(), "FALSE, No bluetooth device with this address", Toast.LENGTH_LONG).show();
                }
            }   
    });  
}

}

I am aware of that this should be done in a separate thread, and yes, I read the Bluetooth Chat example provided by Google.

Can someone help me out?

EDIT

This is the only thing I got from LogCat:

07-06 10:10:22.085: V/BluetoothSocket.cpp(14019): ...fd 63 created (RFCOMM, lm = 26)

EDIT 2

Ok, now got a new error, but its a better error. When i press the connect button, the phone asks for the pin code for pair the devices, but its already paired! After I paired it for the second time, the error says: Connection refused and another exception says, timeout.

  • 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-07T00:54:57+00:00Added an answer on June 7, 2026 at 12:54 am

    you can use this code:Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
    mySocket = (BluetoothSocket) m.invoke(device, 1);

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

Sidebar

Related Questions

I am trying to connect to MySQL using PHP from an Android Device. I
I am trying to writing code so that my android application can query a
I am trying to run Hierarchy Viewer. developer.android.com says to Connect your device or
I am trying to connect the JSF to database. This are the files web.xml
I am trying to connect to a sql database with the following code line
I am trying to write an Android app to connect to an existing web
I am trying to access django project (mysite) on my android virtual device. Content
I am trying to connect Unity with simple Java android development and I actually
I am currently working on an Android app and I am trying to connect
I am trying to create an android app that will connect to various web

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.