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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:25:32+00:00 2026-05-27T05:25:32+00:00

I need to write some kind of client-server application using bluetooth. I need to

  • 0

I need to write some kind of client-server application using bluetooth. I need to create some server on my laptop (I use java and bluecove) which will be send some data to application (on android). Here is my code:

server:

public class OBEXPutServer {

static final String serverUUID = "11111111111111111111111111111123";

public static void main(String[] args) throws IOException {

    LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.GIAC);

    SessionNotifier serverConnection = (SessionNotifier) Connector.open("btgoep://localhost:"
            + serverUUID + ";name=ObexExample");

    int count = 0;
    while(count < 2) {
        RequestHandler handler = new RequestHandler();
        serverConnection.acceptAndOpen(handler);
        System.out.println("Received OBEX connection " + (++count));
    }
}

private static class RequestHandler extends ServerRequestHandler {

    public int onPut(Operation op) {
        try {
            HeaderSet hs = op.getReceivedHeaders();
            String name = (String) hs.getHeader(HeaderSet.NAME);
            if (name != null) {
                System.out.println("put name:" + name);
            }

            return ResponseCodes.OBEX_HTTP_OK;
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
        }
    }
}
}

application:

public class BTTestActivity extends Activity {

String dStarted = BluetoothAdapter.ACTION_DISCOVERY_STARTED;
String dFinished = BluetoothAdapter.ACTION_DISCOVERY_FINISHED;
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
static final String serverUUID = "11111111111111111111111111111123";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);   

    BroadcastReceiver discoveryResult = new BroadcastReceiver() 
    {
        public void onReceive(Context context, Intent intent) 
        {
            String remoteDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
            BluetoothDevice remoteDevice;

            remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            Log.i("@#$%^&*(*&^%$#@#$%^&*(", "WYSWIETLAM");
            Toast.makeText(getApplicationContext(), "Discovered: " + remoteDeviceName + " address " + remoteDevice.getAddress(), Toast.LENGTH_SHORT).show();

            try{
                BluetoothDevice device = bluetooth.getRemoteDevice(remoteDevice.getAddress());
                BluetoothSocket clientSocket = device.createRfcommSocketToServiceRecord(UUID.fromString(serverUUID));
                clientSocket.connect();

            } catch (IOException e) {
                Log.d("BLUETOOTH", e.getMessage());
            }
        }
    };

    registerReceiver(discoveryResult, new IntentFilter(BluetoothDevice.ACTION_FOUND));
}

public void fun(View view)
{   
    bluetooth.enable();

    if (!bluetooth.isDiscovering())
        bluetooth.startDiscovery();
}

}

My problem is that when I try to connect to service from application I get something like this:

11-26 13:41:04.959: E/AndroidRuntime(8830): FATAL EXCEPTION: main
11-26 13:41:04.959: E/AndroidRuntime(8830): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.device.action.FOUND (has extras) } in andr.andr.BTTestActivity$1@40513e00
11-26 13:41:04.959: E/AndroidRuntime(8830):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at android.os.Handler.handleCallback(Handler.java:587)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at android.os.Looper.loop(Looper.java:130)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at android.app.ActivityThread.main(ActivityThread.java:3835)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at java.lang.reflect.Method.invokeNative(Native Method)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at java.lang.reflect.Method.invoke(Method.java:507)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at dalvik.system.NativeStart.main(Native Method)
11-26 13:41:04.959: E/AndroidRuntime(8830): Caused by: java.lang.IllegalArgumentException: Invalid UUID: 11111111111111111111111111111133
11-26 13:41:04.959: E/AndroidRuntime(8830):     at java.util.UUID.fromString(UUID.java:226)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at andr.andr.BTTestActivity$1.onReceive(BTTestActivity.java:44)
11-26 13:41:04.959: E/AndroidRuntime(8830):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
11-26 13:41:04.959: E/AndroidRuntime(8830):     ... 9 more

Do anyone know what is wrong with this code? Thanks for any help.

EDIT:

I’ll run this example what you show to me and I run it but its not work 🙁 I have problem wyth server. He is stops on “StreamConnection streamConnection = connectionNotifier.acceptAndOpen();” line in start method. And hare is log from your android app:

11-26 16:08:32.569: D/MyActivity(2725): ON CREATE
11-26 16:08:32.569: D/MyActivity(2725): ON START
11-26 16:08:32.569: D/MyActivity(2725): INSIDE WHILE STATE ON
11-26 16:08:32.589: D/MyActivity(2725): Start discovery = true
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.589: D/MyActivity(2725): INSIDE WHILE IS DISCOVERING
11-26 16:08:32.619: D/MyActivity(2725): about to connect
11-26 16:18:18.529: D/MyActivity(3166): Connected!

and when I click button I get in log

11-26 16:19:02.389: D/MyActivity(3166): In listener button.

In your app code I change bluetooth adress to my bluetooth device on laptop. Do you know what is wrong, maybe I need to do something else with your code? And I have a question. Where in yout app code u set UUID of server?

I notice that the log from your app is the same even if I dont run server. Its looks like that the appliaction see only bluetooth adapter on my laptop and dont see server application running on my laptop.

BTW. I use BlueSoleil 6.4.149.0 as my bluetooth stack couse my “Toshiba for windows” stack doesnt work with bluecove. Maybe here is problem?

  • 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-27T05:25:33+00:00Added an answer on May 27, 2026 at 5:25 am

    Try looking at my answer: Why am I losing bluetooth client/server connection?

    You should try using reflection when invoking createRfcommSocket:

    Method m = bt.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
    

    I already did a server/client bluetooth connection, and it worked for me. I had similar problems and it turned out to be okay when using reflection.

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

Sidebar

Related Questions

I am using glassfish application server. I need to write the junits for some
I need to write a static method which is performing some kind of parsing
I need to write some data to SQL Server database from Linux in C++.
I need to write some code to stress-test RS232 communication using rxtx ( note
I need to write some kind of loop that can count the frequency of
I need to write a java application that detects a USB device, and can
I need to write some methods for loading/saving some classes to and from a
I need to write some Prolog programs for a class. Any recommendations?
I need to write some javascript to strip the hostname:port part from a url,
I need to write some sql that will allow me to query all objects

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.