Simple Android and Java Bluetooth Application

Last week was my school’s recess week. I had a lot of free time and decided to learn Java and Android Bluetooth by reading the Bluetooth development guide for Android. Then I had an idea to make my Android phone become a simple remote control for my laptop, just for controlling the Power Point slides for presentation. The volume up and volume down become buttons for going to next and previous slide respectively. I write this post to share with you what I have done. I have used Ecipse IDE to write the program.

REMOTE CONTROL SERVER (Java)

Firstly, we need to write the remote control server to receive the signal from Android phone. I used a Java library for Bluetooth called Bluecove to implement the server. You can download the bluecove-2.1.0.jar file and add it to your external library. Note that for Linux, you need to install the bluez-libs to your system and add bluecove-gpl-2.1.0.jar to external library of the project as well (more information here).

Here is my RemoteBluetoothServer class:

The main method creates a thread to wait for connection from client and handle the signal.

In waitForConnection() function, firstly it sets up the server by setting the device discoverable, creating the UUID for this application (the client needs this to communicate with server). Then it waits for a connection from a client. When it receives initial connection, it creates ProcessConnectionThread to handle the client’s command. Here is the code for ProcessConnectionThread:

The ProcessConnectionThread mainly waiting for the client’s inputs and process them. This is simple remote control only for going next/previous of Power Point slide so it only process KEY_RIGHT and KEY_LEFT input. I use Robot class from java.awt to generate the key events.

That’s all we need for the Remote Control Server. When you run the server on a computer, make sure that the Bluetooth is ON.

REMOTE CONTROL CLIENT (Android)

For the client on Android phone, I have followed the guide from Android Dev Guide and the sample Bluetooth Chat application (You can find this application in the android sdk sample folder).

My program is based on the sample application. The DeviceListActivity class is for scanning devices around to find the remote server and connect to it. The BluetoothCommandService class is for setting up the connection and sending the command to our Remote Control Server. These two files are similar to the sample application. In BluetoothCommandService, I have removed the AcceptThread since the client not need to wait for any connection. The ConnectThread is for initializing the connection with server. The ConnectedThread is for sending the command to server.

The RemoteBluetooth class is our main activity for this application:

The onStart() function to check whether the bluetooth on our phone is enabled or not. If not, it creates an Intent to turn the bluetooth on. The setupCommand() to create BluetoothCommandService object to send the command when we push the Volume Up and Down buttons:

That’s it. Now we can run the server, install the application to the phone and run it :-)

You can go to https://github.com/luugiathuy/Remote-Bluetooth-Android to download the project for client and server.

Update: I developed this application using android sdk 2.1. And as comments below, the application is not working with Android SDK 3.x. I don’t have Android tablet to test it yet. Sorry about that.

  • xarmy

    Hello.
    Uuid value from the server

    UUID uuid = new UUID (80087355); / / “04c6093b-0000-1000-8000-00805f9b34fb”
    This was set.
    To actually connect the pc with Android
    UUID uuid = UUID.fromString (“00001101-0000-1000-8000-00805F9B34FB”);
    Write the value of connections.

    However, in fromString method bluecove eopeuni

    UUID value from the server “00001101-0000-1000-8000-00805F9B34FB” To set
    What should I do?

    Please help.

    • http://luugiathuy.com Gia Thuy

      Hi,

      There are two constructor for UUID in bluecove API. For your case, you can use
      UUID uuid = new UUID("0000110100001000800000805F9B34FB", false);
      Note that you need to omit the dash ‘-’.

      You can look at the API here: http://bit.ly/fWJa3n

      Hope it helps.

    • Jonathan

      Hi,

      We are currently looking for freelance mobile app developer, if you are keen please email me @ jonathan@innovatechnology.com.sg

      Cheers
      Jonathan

      • http://luugiathuy.com Gia Thuy

        Hi Jonathan,

        Thanks for your comment. I have emailed you to ask about the project. Thank you! =)

  • Ahmed

    hi Gia
    thank you for this topic , it will help so much .. thanxx :)

    • http://luugiathuy.com Gia Thuy

      You’re welcome, Ahmed. Thanks for your comment =)

  • Rav

    Hi,

    I am running your program on my Windows7 laptop and on my Android. My Bluetooth is one. However my status on the app stays not connected. My Console Output on Eclipse also keeps waiting for connection.

    Is there anything I need to change in your program to make it work?

    Thanks,
    Rav

    • http://luugiathuy.com Gia Thuy

      Hi Rav,
      You open the menu of the app and click on “Connect a device”, then click on the button “Scan for devices” to find your laptop and connect to it. You also need to make sure that your laptop’s bluetooth is discoverable so that the phone can find it.
      You don’t need to change the program.

      • Rav

        Thanks for the quick reply. I didn’t realize I need to open the menu to connect. It works like a charm.

        Rav

  • Kostas Akas

    Hallo ,

    I’m trying to use the two projects to connect my android phone with the PC, but in the android application cannot connect with the PC! I click on connect a device, it finds my PC’s bluetooth and it’s always saying can’t connect to the device.
    I haven’t touched anything in the source code. I just run the java application from my laptop,( my bluetooth in laptop is on of course)and then i try to connect from mobile…
    maybe i do something wrong, but i don’t know what…help please!!!

    • http://luugiathuy.com Gia Thuy

      Hello,
      I just try to download the source and run it again. It’s OK. Can you try to unpair your phone and laptop (Right click on bluetooth icon at system tray, choose “Show Bluetooth Devices”, right click on your phone and remove it) then pair them again? Hope it will work for you.

      • Ablessia

        Hai Gia Thuy,
        Thank you for your app.
        I have the same problem as Kostas, and I have try re-pair and also on both windows XP and windows 7, but it doesn’t work. :/
        Just wanna ask what Android version you are using? Mine is 2.2.1

        • http://luugiathuy.com Gia Thuy

          Hi Ablessia,
          When I wrote this app, I was also using Froyo 2.2 on my phone. Can you try to look at the LogCat when you run your program via Eclipse? You need to switch to DDMS perspective to see the LogCat.

          • Ablessia

            Thank you for your reply. Here is the LogCat.

            04-10 22:31:06.989: INFO/ActivityManager(59): Start proc com.luugiathuy.apps.remotebluetooth for activity com.luugiathuy.apps.remotebluetooth/.RemoteBluetooth: pid=289 uid=10037 gids={3001, 3002}
            04-10 22:31:07.030: INFO/AndroidRuntime(279): NOTE: attach of thread ‘Binder Thread #3′ failed
            04-10 22:31:07.680: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
            04-10 22:31:07.800: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
            04-10 22:31:08.070: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x300418:0x3005e0] in 5757116 ns
            04-10 22:31:08.150: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x333b30:0x333c3c] in 627039 ns
            04-10 22:31:08.810: DEBUG/AlarmManagerService(59): Kernel timezone updated to 0 minutes west of GMT
            04-10 22:31:08.830: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 33547 ms (total 33547 ms)
            04-10 22:31:08.840: DEBUG/SystemClock(127): Setting time of day to sec=1302474669
            04-10 22:31:09.284: WARN/SystemClock(127): Unable to set rtc to 1302474669: Invalid argument
            04-10 22:35:55.695: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
            04-10 22:37:19.514: DEBUG/dalvikvm(128): GC_EXTERNAL_ALLOC freed 2295 objects / 106776 bytes in 63ms
            04-10 22:37:24.854: WARN/KeyCharacterMap(128): No keyboard for id 0
            04-10 22:37:24.854: WARN/KeyCharacterMap(128): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
            04-10 22:37:30.835: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10200000 cmp=com.luugiathuy.apps.remotebluetooth/.RemoteBluetooth }
            04-10 22:37:31.334: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43f55ad0
            04-10 22:37:36.705: DEBUG/dalvikvm(289): GC_EXPLICIT freed 887 objects / 64168 bytes in 142ms
            04-10 22:37:57.935: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10200000 cmp=com.luugiathuy.apps.remotebluetooth/.RemoteBluetooth }
            04-10 22:37:58.275: DEBUG/dalvikvm(59): GREF has increased to 301
            04-10 22:37:58.495: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44017628

            04-10 22:31:06.989: INFO/ActivityManager(59): Start proc com.luugiathuy.apps.remotebluetooth for activity com.luugiathuy.apps.remotebluetooth/.RemoteBluetooth: pid=289 uid=10037 gids={3001, 3002}
            04-10 22:31:07.030: INFO/AndroidRuntime(279): NOTE: attach of thread ‘Binder Thread #3′ failed
            04-10 22:31:07.680: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
            04-10 22:31:07.800: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
            04-10 22:31:08.070: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x300418:0x3005e0] in 5757116 ns
            04-10 22:31:08.150: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x333b30:0x333c3c] in 627039 ns
            04-10 22:31:08.810: DEBUG/AlarmManagerService(59): Kernel timezone updated to 0 minutes west of GMT
            04-10 22:31:08.830: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 33547 ms (total 33547 ms)
            04-10 22:31:08.840: DEBUG/SystemClock(127): Setting time of day to sec=1302474669
            04-10 22:31:09.284: WARN/SystemClock(127): Unable to set rtc to 1302474669: Invalid argument
            04-10 22:35:55.695: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
            04-10 22:37:19.514: DEBUG/dalvikvm(128): GC_EXTERNAL_ALLOC freed 2295 objects / 106776 bytes in 63ms
            04-10 22:37:22.114: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10200000 cmp=com.example.android.BluetoothChat/.BluetoothChat }
            04-10 22:37:22.364: INFO/ActivityManager(59): Start proc com.example.android.BluetoothChat for activity com.example.android.BluetoothChat/.BluetoothChat: pid=445 uid=10036 gids={3001, 3002, 1015}
            04-10 22:37:23.074: ERROR/BluetoothChat(445): +++ ON CREATE +++
            04-10 22:37:23.534: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43e2e888
            04-10 22:37:23.924: ERROR/BluetoothChat(445): — ON DESTROY —
            04-10 22:37:24.854: WARN/KeyCharacterMap(128): No keyboard for id 0
            04-10 22:37:24.854: WARN/KeyCharacterMap(128): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
            04-10 22:37:30.835: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10200000 cmp=com.luugiathuy.apps.remotebluetooth/.RemoteBluetooth }
            04-10 22:37:31.334: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43f55ad0
            04-10 22:37:36.705: DEBUG/dalvikvm(289): GC_EXPLICIT freed 887 objects / 64168 bytes in 142ms
            04-10 22:37:57.935: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10200000 cmp=com.luugiathuy.apps.remotebluetooth/.RemoteBluetooth }
            04-10 22:37:58.275: DEBUG/dalvikvm(59): GREF has increased to 301
            04-10 22:37:58.495: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44017628

            I have try the PRemoteDroid (http://code.google.com/p/premotedroid/) and succeeded. I just curious where went wrong on this one. Cheers.

    • Leslie

      Hey… i figured it out… change the UUID address in the BluetoothCommandService.java in the client side andro app and the Wait thread() in the server jar side…

      Make sure that the UUID in the client side is of the form 00001101-0000-1000-8000-00805F9B34FB and in the server is 0000110100001000800000805F9B34FB … just replace the existing UUID’s with the one I have mentioned here… pl let me know if this has worked, cos it worked for me… All the best amigos :-)

      Ps. Thnx a million for the initiating code and inspiration Gia… Tc

  • Ahmed

    Hi again :)
    i tried your apps and it seems to be very good, but i found a problem prevent me to run your apps..
    my buetooth stack is Broadcom which not supported by Bluecove library ,andi found this line in bluecove runtime Requirements :
    *A Bluetooth device supported by the WIDCOMM, BlueSoleil or Microsoft bluetooth stack .
    check this (bluecove runtime Requirements):
    http://code.google.com/p/bluecove/wiki/Documentation
    so i’m confused from these things … and i want a solution for this problem .. could help :) ?

  • Ehab

    Hi Gia,

    Thanks for your effort, I want to ask if I can use this code with some modifications in my work?

    • http://luugiathuy.com Gia Thuy

      Hi Ehab, you are free to use my code :-) If possible, can you share with me what you are doing? :-)

      • Ehab

        an application to use android powered mobile to do some tasks in pc using bluetooth connection

  • pradito

    hi gia thuy…
    I just want to ask about your source code,, I applied that in eclipse…
    I was tried, but I can’t run this program.. can you teach me how to run and apply with android phone?

  • pradito

    hi…Gia
    I have installed application in my android phone…but can’t connect with my PC..
    I have no idea, I just copy your code in android SDK..using android 2.2 froyo..
    but still get stuck…
    can you show the screen shoot?

    • http://luugiathuy.com Gia Thuy

      Hi Pradito, what is the message when you connect the phone with PC?
      When you open the application, press the menu, and choose “Connect to a Device”, then you search for your PC (your PC’s bluetooth needs to be turned on and set it to discoverable) and connect.

      Hope it helps.

      • pradito

        I have check it, but the message is, “unable to connect device”..
        I tried to installed bluetooth driver else, so I have broadcom now…but still doesn’t work..
        I have a question, is the server haven’t user interface ? I Run the server application and this is the message in console:
        BlueCove version 2.1.0 on winsock
        04c6093b00001000800000805f9b34fb
        waiting for connection…

        I tried to send a file from phone, it is mp3…and it successful…why the remote application in my android can’t connect to my PC?

        please I need ur help ASAP,, thanks

  • Nabil

    Hey,

    Can you please tell how to run your application on the server side pc………………..

    • http://luugiathuy.com Gia Thuy

      Hi Nabil,
      You use eclipse to import the project, then you can run it. Hope it helps.

  • RG

    Just wanted to say thanks for putting this code up. I’m working on a Bluetooth MIDI controller, and your code has really helped to understand the underlying principles. Is there a way I can donate/flattr?

    • http://luugiathuy.com Gia Thuy

      Hi RG, thank you for your comment. It really make me happy. These are my personal projects and I’m happy to share with other people, feel free to use my code (=
      It’s good if you can share with me what you are doing so we can discuss about it (-:

  • Mike

    Hey, Gia
    I am trying to create an app to receive information via bluetooth from a chip. I was hoping you could help me get started.

    • http://luugiathuy.com Gia Thuy

      Hi Mike, I think you try to search Bluetooth API for your chip, and try to create a simple program to connect two devices first. From that, you can expand the program to do what you want. Can you tell me more about the chip? Which chip are you using?
      Hope it helps.

  • Dhruv

    Hey Thuy,
    I am totally new to android,so can you explain me how to deal with “package name” that is asked when we select new android application in Eclipse??
    And other similar things to be filled other than package name…

    Also help me how to deal with the code you demonstrated above in my eclipse in brief….

    Thank you…

  • Ahmed

    Hi Gia
    I used your app and i have a problem, i want to cancel the listening of the server in notifier.AcceptAndOpen();
    I tried notifier.close() and connection.close() after accept the connection but it throws a nullPointerException

    I tried to break the while loop but the AcceptAndOpen() method is a block method so it didn’t work with me.
    Also I tried to close the WaitThread using stop() but it didn’t work because of the same reason of blocking method..(i know using stop is unsafe but it is for test), I used WaitThread.interrupt() but it didn’t work..

    In general:
    I want to disconnect the connection from the server side.
    I tried a lot of things , so can you help me?

    Thanks in advance :)

  • Rajni Sharma

    Hello Gia,
    i am working on an android application that display the list of all bluetooth enabled devices and then i want to send a file to the selected device which was chosen from the list. i have also tried the Bluetooth Chat application (like inbuilt bluetooth functionality of mobile).according to chat example we required remote server but in my application my phone worked as client i dont understand who is remote server for my device . it is not possible to run remote server code on every mobile .in your application you run remote server code on your pc and remote control client on your mobile.please help me. if you have any sample application or code to transfer file from android mobile to any bluetooth enabled device.
    Thanks in advance

  • Dhruvin

    Hi Thuy,

    I tried your BluetoothServer code and it works perfectly fine and awaits a connection from the Android device.
    However, compiling and running the Android code on my Android 2.2 device, forces the application to stop unexpectedly.
    What could be the possible reason?

    Thanks for your help.
    Dhruvin

    • http://luugiathuy.com Gia Thuy

      Hi,
      It’s strange. Can you give me the errors in Eclipse. You can get them by open LogCat windows in eclipse. Thanks.

  • Hoang

    Hi Thuy,
    I tried your code. It successfully run on both client and server (The client and server are both Android 3.1). However the connection is failed every attempted.
    I use Eclipse to debug it and found that the exception happen when you call mmSocket.connect(); line 259 @ run() @ConnectThread
    I added code below
    Log.i(TAG, “Error: run()@ConnectThread_class” + e);
    to the catch statement and I got message below

    07-13 21:32:04.324: INFO/BluetoothCommandService(24634): Error: run()@ConnectThread_class java.io.IOException: Service discovery failed

    What did I do wrong?
    Thanks
    Hoang

    • http://luugiathuy.com Gia Thuy

      Hi Hoang,
      You need to turn on the bluetooth on server and make sure that it is discoverable.
      To connect to server, choose “Connect a device” on client and select the server you want to connect. You may need to pair two devices by entering a code.
      Hope it helps.

      • Hoang

        Hi Thuy,
        Thanks for reply. Your suggestion is a fundamental procedure that can’t be missed. I am sure that I did all those steps. I download the bluetooth chat from market, and it is working just fine. However, your code and bluetooth chat from Androidandroid-sdksamplesandroid-12 seems having the same problem.
        Did you try it in android 3.1? I don’t have android 3.1 source code, so I can’t dig further down
        I also develop similar app in App inventor, and I have no problem at all, but when I try to develop this app in Java, then it does not turn out right
        Please note that there is no new modification in your code.
        Thanks for your help
        Hoang

        • Hoang

          Hi Thuy,
          I checked that one of my tablet has version 3.1 and another is 2.2. Does it cause a problem?

  • JINESH

    Hi Thuy…
    I started the application from server(Windows XP) and its giving “waiting for connection”. Then i started the client application in Android device(version 2.3) but its giving error “The application RemoteBluetooth(process com.luugiathuy.apps.remotebluetooth)has stopped unexpectedly. Please try again.”
    Note: Bluetooth is On and discoverable.

    Reply Pls…
    Thanks
    Jinesh

  • http://www.hhms.org Rao

    Hi,
    REMOTE CONTROL SERVER class is not working on my i5 but it perfectly working on pentium 4 ..
    javax.bluetooth giving problem…
    please guide me

  • hungson

    hi when i run in command line
    i show list error i don’t know why
    please help me

    Exception in thread “main” java.lang.NoClassDefFoundError: main
    Caused by: java.lang.ClassNotFoundException: main
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: main. Program will exit.

  • testing android

    hi..could you guide me how to shutdown the pc through android over bluetooth..

  • Justin

    Hi Luu, First of all, I’d like to thank you for your great program. I am developing an android application, and I have tried your example code to practice, and it works great on the motorola droid x. however, on the newer phones like the evo 3d and the samsung galaxy s2, it says it is unable to connect. it pairs, but doesnt connect. Any thoughts or suggestions?

    • http://luugiathuy.com Gia Thuy

      Hi Justin, let me check with the newer android sdk first. Will let you know soon. Sorry for my late since I’m quite busy now.

  • saravanan

    hello sir
    how to run this program in eclipse, please help me sir

    • http://luugiathuy.com Gia Thuy

      Hi! you import the project from ecipse, you can run it.
      You also need to install the android sdk and android plugin for eclipse.

  • Sunny

    Hey Hoang,
    thank you for the above information, it is useful.
    I would like to ask that I do not find using the RTS, DTR, DSR or CTS control signal in the above. Is it better if using it? Or, there is no way to access the control signals in Android API?

    • nadhirah mustafa

      Hey guys, I tried it and it worked on my pc. after pairing and connecting the server with the device, you open the app first and you have connect again using the menu button – select connect a device.

      IT WORKS! thanks thuy!

  • sachin

    hi,
    whenever i run server program i get below error,

    # A fatal error has been detected by the Java Runtime Environment:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d9ad8e5, pid=2820, tid=3632
    #
    # JRE version: 6.0_17-b04
    # Java VM: Java HotSpot(TM) Client VM (14.3-b01 mixed mode, sharing windows-x86 )
    # Problematic frame:
    # V [jvm.dll+0xfd8e5]

    i tried to debug code and then i found the cause of error is…
    connection = notifier.acceptAndOpen();

    pls help

  • Mohanraj

    Do You Have any Idea to Send Files through Bluetooth in Android. and Have to Send File Details And Have to Receive the Files On Other Device by the Application… If u Know Please Help me….

  • Steve Peterson

    Thanks Thuy!

    I got this to work without issues importing your code into Eclipse on a Mac. This is my first stab at Bluetooth, and your code was very easy to follow.

    • http://luugiathuy.com Gia Thuy

      You’re welcome Steve. Thanks for your comment =)

  • androidCoder

    Hello,

    I am getting this error in eclipse:
    Native Library bluecove_x64 not available

    I am working on ubuntu, and I also installed bluez-libs (http://www.bluez.org/download/) following the instructions they gave.

    What can be the problem, any idea?

  • effy effy

    Hi
    thank you for your code^^
    I have a question.
    My pc waitng android connect.(Client).
    —————————————-
    BlueCove version 2.1.0 on winsock
    04c6093b00001000800000805f9b34fb
    waiting for connection…
    ————————————————-
    client .apk install on my android phone.
    but I can’t uenable to connect device
    what do i?
    My PC,android phone to be pairing.
    but not connected…
    help me~~~~~~~~~~~~~~~~~

  • http://sudarmuthu.com Sudar

    Hello,

    Thanks for sharing the code.

    I have made some enhancements to your code and have also fixed a bug. I have sent you a pull request in github. Would appreciate if you could pull in my changes.

    • http://luugiathuy.com Gia Thuy

      Thank you very much Sudar! I will pull your changes soon. May be this weekend. Thanks again! =)

    • akki

      Hiiiie………….

      M sure u can help me………..thnx in advance

      basically………….M trying to implement “Remote Desktop Access on Mobile via bluetooth”,
      ie. We can control our pc on android phone
      and has very little time left to finish it of…

      Right now i am still struggling with the “Bluetooth Connection Setup”
      especially because of the (1)”ForceCLOSE ERROR”,I have included Exceptions Which never pops up
      (2)I am unable to test my app on laptop every time I use mobile to test.

      (3)As of now there is some problem At the mmsocket.connect() function call on android code.

      (10)now when i try to execute this CODE given here……It gives error “Unable to Connect”

      Any ideas, Help, Links, blessings :p are welcomed………
      PLz do share your views and

      Thanks and Regards
      Akshay Mane
      a k s h a y 4 4 9 7 m a n e @ g m a i l . c o m

      plzzzzzzz take ur time n Help me………

  • Sajol

    String url = “btspp://localhost:” + uuid.toString() + “;name=RemoteBluetooth”;
    sir,please explain the line meanings as soon as posible.
    if i use xammp for local server in windows what is syntax of the above line.
    please sir help me

  • androidbeginner

    Thanks for sharing !! :D

  • paranoidAndroid

    Hi ! Thanks for sharing your code!

    I am trying to write an android application to connect and send commands to a roomba robot. You have both server and client side code for the application but in my case there will be no server side code. How can I connect my phone to the robot in this case? Will changing the UUID in the client code be enough?

    • http://luugiathuy.com Gia Thuy

      I think the roomba robot is the server in this case. You need to find a way to send message from your phone to the robot. I’m not sure how to connect to roomba robot.

  • Andrei

    I have imported your projects (server and android app) into eclipse, installed the app on my galaxy s and then ran it. My problem is that I cannot connect my device to the server, i keep getting the “unable tot connect” (the phone is paired to my computer). I have tried it on my macbook pro with OSX Lion and wiondows 7 64 bit (on both OSes i used both versions of eclipse for building the programs – 32 and 64 bit) but no luck….I even tried it on XP 32 and nothing….
    Any ideas?

  • Stephen

    Thnx Thuy!! you saved half of my graduate project!! now i finally have a start up

    • http://luugiathuy.com Gia Thuy

      Hi Stephen, you’re welcome! I’m glad to hear that =) Good luck to your project!

    • Vic

      Same over here. Thanks. I din’t really believe I will find somthing like this.

  • Uday

    Hi Thanx man its really cool. I have a question though, I am trying something exactly opposite of it.
    My android application will load/fill up text boxes by getting input from windows server via bluetooth.
    Do you have any pointers for that. I have connection established but I am unable to process text stream on android device.

    Thanks again !!

  • Will

    Hey,

    My senior design project revolves around something like this, which I did not expect to find. I thought it might’ve been a bit more difficult (since my part is the client side). I want to enhance this a bit and add security and other features. Thanks a lot of posting this.

    -Will

    • http://luugiathuy.com Gia Thuy

      You’re welcome Will! =)

  • praneetha

    Hi Thuy!
    I am from NUS also. I am developing an application for my FYP in android. It involves bluetooth communication to an external hardware that my partner is developing. While communicating to an external harware bluetooth model, I am facing trouble with my application. My phone is able to receive the data over the bluetooth. However, my application is not able to receive it. As in, the data is stored in the phone memory instead of the application.
    I am wondering if you can help me out. I research a lot about this, but could not find an appropriate solution.
    Thank you!

  • Marek

    Hey
    I have quite big application in C# and I would need my phone with android to be able to send orders to this application, do you know any tutorials or some good library where I could build simillar “server” application in C# and implement it to my app, so I could connect to it with this bluetooth app for android ?

    Thanks for help in advance

  • Jesús

    Hello, first of all, this is an awesome work, and I’ve made an amazing project with this, and some electronics, but I have to ask something, how do I do for sending a byte or int, back from the PC to android device?. Thanks.

  • Stephen

    Thnx again! i got my project done! it was a great help ,

    P.S.
    i was thinking to write a server inside the phone while the computer links to the phone it will make the phone into a mouse, any ideas?

    the idea’s step
    1. phone(open app)[wifi opened and linked to local]
    2. open web brower and type in the local ip the phone gave
    3. and a sec poof! the phone has turned into the mouse

  • Saleh

    Hi Thuy,
    Thanks for this great post,
    I’m trying to connect throw my glucose meter to my android application,
    But I can not reach the solution untill now !
    If you do not mind, I need you help : )

    waiting for your response, and thank you.

  • Chris

    Hi Thuy,

    Thank you very much for sharing this example. I was able to built / run it on my Acer Iconia A500 running Android 3.2.

    Best regards,
    Chris

  • Edwin

    Hello. I’m working on an android app which involves bluetooth. I’ve alr completed the code but it doesnt work and i got no idea why. Could you take a look at it?

  • manisha

    hi…..,

    i want to know something……,
    Is Bluetooth support emulater?
    if i hv not real device so m i run application in emulater….?
    How can i check my application?

    • akki

      hi manisha……………nice to meet u :p

  • Thullyo

    Hi,

    I am trying to run the RemoteBluetoothServer but an exception saying that “Bluetooth device is not ready” is shown even that the device is ready. I am capable to locate my two devices.

    Please, help me.

    Thanks.

  • Kothandraman

    i am installed .apk file in android mobile while start application bluetooth is not connected pls tell me?

  • Tejas

    Hi….Thuy,
    Your code is really helpful, but i have a problem , when i run both the server-side and client-side apps provided by you, on the client side it shows the toast of getting successfully connected to my PC. But on the server side console i m getting message
    BlueCove version 2.1.0 on bluesoleil
    04c6093b00001000800000805f9b34fb
    waiting for connection…

    I think the acceptAndOpen() is not returning the connection ………the help would really be appreciable.
    Thank You in advance

  • BITS

    hello. . .
    i want to make a connection between a microcontroller chip aided with bluetooth device and and therefore to develop an android app to send information. . .can u please help me. ..

    your concern will be helpful in my project. . .thanking you

  • Wiktor

    Hi,

    Thank you for sharing this tutorial, it’s very helpful. I have similar project to yours – it’s android bluetooth remote for winamp. I’m trying to learn how to establish bluetooth connection from your application, but I have problem at the very begining – client can not connect to a server (there’s “unable to connect device” message). When I run server in eclipse it seems to be alright ( there is “waiting for connection” message).
    I have windows 7 (64 bit) with widcomm bluetooth, eclipse (32 bit), sdk (32 bit) and adnroid 2.3.5 on HTC DESIRE HD, what can be problem?

    Please reply me as soon as you can, because I have my deadline just behind my back.

    Ps. Sorry for language mistakes.
    Best regards,
    Wiktor

    • Leslie

      Welcome to my same world of problems bro… I have exactly the same problem… did u try generating the manifest file when exporting your server…??

      Also… did u manage to solve the problem…??

  • Wiktor

    Hi,

    I had same problem as many people here – I couldn’t connect my phone to server.
    The solution was very simple – I’ve chanched UUID to another from UUID online creator.
    Maybe this will help somebody.

    Thank you again for sharing your work.

    Regards,
    Wiktor

  • Pop Ioan Mihai

    Hi,
    Nice tutorials, but i have a little question. I`ve tried your example from https://github.com/luugiathuy/Remote-Bluetooth-Android client example and when i try to write somethig(after succefully i am connected to the remote device), I get Connection reset by peer.
    Thanks.

  • Leslie

    Hey Gia… amazing program… made it as simple as possible and as effective… thnx a million :-)
    I am currently working on a project to create an android app as a mousepad and keyboard for any laptop or pc with docks for module additions such as volume controls, shut down options, etc which can be added by any interested andro nerd…
    I have finished the design, but am stuck at the back-end… can u pl help me conceptually by telling me how i can implement your project over wifi rather than bluetooth…?? It would really help me a lot… Thnx again man… Tc

    • Leslie

      Hey… i figured it out… change the UUID address in the BluetoothCommandService.java in the client side andro app and the Wait thread() in the server jar side…

      Make sure that the UUID in the client side is of the form 00001101-0000-1000-8000-00805F9B34FB and in the server is 0000110100001000800000805F9B34FB … just replace the existing UUID’s with the one I have mentioned here… pl let me know if this has worked, cos it worked for me… All the best amigos :-)

      Ps. Thnx a million for the initiating code and inspiration Gia… Tc

      • akki

        Hiiiie
        congrats for u figuring out solution.

        M sure u can help me………..thnx in advance

        basically………….M trying to implement “Remote Desktop Access on Mobile via bluetooth”,
        ie. We can control our pc on android phone
        and has very little time left to finish it of…

        Right now i am still struggling with the “Bluetooth Connection Setup”
        especially because of the (1)”ForceCLOSE ERROR”,I have included Exceptions Which never pops up
        (2)I am unable to test my app on laptop every time I use mobile to test.

        (3)As of now there is some problem At the mmsocket.connect() function call on android code.

        (10)now when i try to execute this CODE given here……It gives error “Unable to Connect”

        Any ideas, Help, Links, blessings :p are welcomed………
        PLz do share your views and

        Thanks and Regards
        Akshay Mane
        a k s h a y 4 4 9 7 m a n e @ g m a i l . c o m

        plzzzzzzz take ur time n Help me………

        • Sai

          Hi Akki,
          As far as I can see its “unable to connect” due to the fact that android emulator doesnt support bluetooth. I am sure you are aware of this; still a reminder. Hope it helps.

      • dude

        Hi Leslie,
        I managed to get the regular Bluetooth example working thanks to Gia!

        I am trying to understand what is the difference of your example above? Can you please explain what is the difference ?Thanks!

    • http://luugiathuy.com Gia Thuy

      Thanks for your solution Leslie =)

    • thai_tam_2406

      Hi Leslie.
      You can share project android app as a mousepad and keyboard.I very need this project.
      Thanks you very much.

  • JR Gapuz

    I have this GPS application.. i want to trigger the gps application with the help of the data received via bluetooth.. is there any that the received txt file or signal could be able to trigger the gps/location manager in the android application? any links that would help me on developing this application?

  • abdo serag

    Hi
    Thanks for the magnificent program, i tried to implement it, but caught some errors !!
    Help me plz ASP.
    and that is a pic of my errors
    http://www.mediafire.com/imageview.php?quickkey=tgwmhg8ok5m3yw8
    thanks in advance
    Exception in thread “Thread-0″ java.lang.UnsatisfiedLinkError: com.intel.bluetooth.BluetoothStackToshiba.getLibraryVersion()I
    at com.intel.bluetooth.BluetoothStackToshiba.getLibraryVersion(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.setBluetoothStack(BlueCoveImpl.java:939)
    at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:482)
    at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
    at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
    at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
    at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
    at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
    at com.luugiathuy.apps.remotebluetooth.WaitThread.waitForConnection(WaitThread.java:31)
    at com.luugiathuy.apps.remotebluetooth.WaitThread.run(WaitThread.java:18)
    at java.lang.Thread.run(Unknown Source)

    • Rahul Kundu

      Hi Gia
      I am facing same problem as abdo. If you got any solution please help me.
      Thanks and regards
      Rahul

      Error Details

      Exception in thread “Thread-0″ java.lang.UnsatisfiedLinkError: com.intel.bluetooth.BluetoothStackToshiba.getLibraryVersion()I
      at com.intel.bluetooth.BluetoothStackToshiba.getLibraryVersion(Native Method)
      at com.intel.bluetooth.BlueCoveImpl.setBluetoothStack(BlueCoveImpl.java:939)
      at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:482)
      at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
      at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
      at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
      at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
      at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
      at com.luugiathuy.apps.remotebluetooth.WaitThread.waitForConnection(WaitThread.java:31)
      at com.luugiathuy.apps.remotebluetooth.WaitThread.run(WaitThread.java:18)
      at java.lang.Thread.run(Unknown Source)

  • Prajakta

    Hi Gia,

    I tried to run this application. Initially I was also facing the same problem; android app was showing a message “unable to connect”, when i was trying to connect it with java app on my laptop.

    I found the solution on : http://stackoverflow.com/questions/5615186/trouble-coneccting-pc-with-android-2-1-mobile-for-the-bluetooth-chat-example
    and now it is able to connect. But now I am facing a new problem… even if android app is connecting to laptop bluetooth, java app is not responding at all.
    in waitThread.java , app is running without any problem till connection = notifier.acceptAndOpen();
    but once bluetooth connection happens, its not hitting any breakpoint at all.
    Can you help me out??

    Thanks in advance :)

  • Prajakta

    Hi Gia,

    I tried to run this application. Initially I was also facing the same problem; android app was showing a message “unable to connect”, when i was trying to connect it with java app on my laptop.

    I found the solution on : http://stackoverflow.com/questions/5615186/trouble-coneccting-pc-with-android-2-1-mobile-for-the-bluetooth-chat-example
    and now it is able to connect. But now I am facing a new problem… even if android app is connecting to laptop bluetooth, java app is not responding at all.
    in waitThread.java , app is running without any problem till connection = notifier.acceptAndOpen();
    but once bluetooth connection happens, its not hitting any breakpoint at all.
    Can you help me out?

    Thanks in advance :)

    • dude

      Did you figure this out I am having the same issue….

    • Ali

      Very Thanks!
      My problem has been solved :)

  • mohamed

    thank you very much for this app
    but i need some help the app is connecting but it when attemp to close it in
    mobile the mobile go hang and i try it more and more but without any work

    please help and thank you for advance

    • saif

      has anyone found the reason why the phone hangs while you close/move out of this application using back button?

  • gani

    i want a sample program for building a app which should send predefined character using bluetooth
    when a butten is pressed in android phone… thanking u…

  • Aparna

    hi i’m beginner in android even java too i have neared my dead line to submit a android project regarding bluetooth i tried o implement yours but i get parser on running the apk in my mobile can u send me a working model or could you explain me the code i request for possible reply as soon a possible. while implementing the server stays at waiting for connection but on running the apk i get parser error. so i tried manual pairing but the server stays at same position :( it will be very grateful if you send a positive reply as soon as possible

  • http://olioul.wordpress.com/ Md. Olioul Islam Rahi

    Hi,
    Can any one please give me the Zip file of the project (Both Client and Server)
    Thanks in advance.

    -Rahi.

  • Rushabh Patel

    hi,
    i have used this application to make one bar code scanner in android which scans the code and send the bar code directly to the desktop JAVA application Bluetooth server Via Bluetooth.
    but when i run both application then its connected fine but when i send bar code on button click its not sends the MSG to desktop but yes if i minimize the android application desktop server receives that code instantly.
    It seems funny but that is problem and i can not figured out this yet. So if you have any solution or idea then please tell me.

  • Kieth Boyd

    I was wondering if anybody solve their problems with bluetooth? I working this app that keep score bluetooth.
    thanks

  • Akki

    thanx buddy……………thts for remote work

  • akki

    Helllo everyone
    rushabh,thuy,aparna,prajakta

    tHANX alot………….M trying to implement “Remote Desktop Access on Mobile via bluetooth”,
    ie. We can control our pc on android phone
    and has very little time left to finish it of…

    Right now i am still struggling with the “Bluetooth Connection Setup”
    especially because of the (1)”ForceCLOSE ERROR”,I have included Exceptions Which never pops up
    (2)I am unable to test my app on laptop every time I use mobile to test.

    (3)As of now there is some problem At the mmsocket.connect() function call on android code.

    (10)now when i try to execute this CODE given here……It gives error “Unable to Connect”

    Any ideas, Help, Links, blessings :p are welcomed………
    PLz do share your views and

    Thanks and Regards
    Akshay Mane
    a k s h a y 4 4 9 7 m a n e @ g m a i l . c o m

    plzzzzzzz Help………

  • Marco

    Hi,
    I´m from Brazil and found your site on google.
    I implemented your Server code in my Android aplication, but it didn´t work,
    something about the bluecove… You didn´t design the Server to be running in a
    mobile right?
    How can I adapt this to make it work?
    Can you help?

    Please reach me by email, ok?

    • http://luugiathuy.com Gia Thuy

      Hi Marco, Yes I’ve implemented the Server to be run on PC, not mobile device. If you want a server on an Android phone, you can look up the Bluetooth Chat Example on Android Development. Hope this helps!

  • Alice

    Hello,
    I just wanted to ask why the device connection is lost when we press back button or home button. Would running the whole app as a service solve the problem? How else can we solve this?
    Thanks you very much.

  • Avseq

    Hi, i am a beginner in Android development. I just successfully implemented this app. thanx a lot for that. But i want to ask one question.
    How can i add swipe gestures to control the slides in the app?

    please help….

  • kishore

    I want send a file from server PC to android phone via bluetooth , please help me it is my final year projrct . I am even ready to pay money if you want.

    • http://luugiathuy.com Gia Thuy

      Hi! May I know what problems you’ve encountered so I can help?
      The idea is similar to this app. You send byte data of the file from your PC to the phone.

      • kishore

        I have used OBEX protocol for send file.

      • kishore

        Hi , i am doing engg in BMS College Of Engg Bangalore. I am currently in final year (computer science branch), i am doing a project called “restricting android mobile phone features inside college campus(ie blocking multimedia features) “, for that i have to send application to android mobile using bluetooth when mobile is inside campus . I know it can be done using OBEX protocol and i am able to send files to NOKIA phones but android phones are not receiving , please help me in sending application to mobile phone using bluetooth or even other suitable means for this project , i am ready pay money for that . Please help me , i am stuck with my project.

      • kishore

        sorry i sent many msgs , thanks for quick reply i have implemented code in netbeans , i am able to send file to NOKIA phones but for android phones it gives an exception saying “selected device is down” . suggest me how i can modify your code to work for my project , plz and thanks in advance.

  • kishore

    thanks for the quick reply , i have implemented code in netbeans . It is sending file to NOKIA phones but for android phones it says “selected device is down”. please help me, or tell me how to modify this code suitable to my project. Thanks a million in advance.

  • Shivika

    Hi Gia,
    I am very thankful that you shared the code.But there is a problem the code is working only till
    BlueCove 2.0.1 version
    wating for connection….
    plzz tell me how to proceed after this.

    thanks a ton (in advance) :)

    • http://luugiathuy.com Gia Thuy

      Hi Shivika,
      That is the server program. It’s waiting for connection from a phone. You need to run the app on your android phone and pair the bluetooth with your laptop. Then you can use your phone to remote the laptop as I’ve explained above. Hope it helps!

      • shivika

        Thanks Gia for quick reply but the problem is I have a problem, when I try to connect my mobile device a Toast appears saying “unable to connect device” .
        plzz help me with this

        • http://luugiathuy.com Gia Thuy

          Hi Shivika, Can I make sure that you connect to correct laptop which runs the remote bluetooth server program? Your laptop’s bluetooth need to be discoverable so that the phone can search and connect to.

          • teddy

            strange, i also have the same problem with shivika here, i managed to compile the apk and jar file, and run the server,it says waiting for connection, but then when i try to connect with the phone, it say unable to connect to device. i already make the laptop to be discoverable though, any idea? or log where i can look into?

  • Miguel

    Hi all,

    First of all thank’s for the code, is great!
    I have a problem, when I try to connect my mobile device a Toast appears saying “unable to connect device” Can someone help me?

    Thanks a lot.

    • krish

      I too have the same problem as Miguel has plzz help us…

      • Atreiu

        I have the same problem! :-( Any solution?? Thanks!!

  • swathi

    hi …
    I am a 3rd year BE student from Information science branch, presently i m working on an application on video streaming via bluetooth for the android platform. Basically my aim to play the same video simultaneously in two android phones via bluetooth(this doesnt involves real time streaming). I tried the basic bluetooth chat code from developer site to establish the connectivity, but i could’nt make it .i m done till the pairing .Can you please help me regarding this .If you have any idea on video streaming via bluetooth ,then please let me know.
    thank you in advance…,

  • Gaurav

    Hello! I am a 3rd year student from Pune and i am working on a project related to Bluetooth.
    Actually, we have created a BOT with wheels and we want to run that bot from our android phone.
    I just had some doubts regarding the sending of bluetooth signals(as to which type of commands) to the controller.
    We have 4 buttons viz Forward,Reverse,Left,Right.
    How do i send any signal with the pressing of these buttons ?? Please Help!
    Thnx in advance! :)

  • Dim itar

    Very good! Thank you!

  • teddy

    Hi,
    It’s me again. after much googling, I managed to connect to the PC. the only changes i made is by changing the uuid to 00001101-0000-1000-8000-00805F9B34FB for both server and client side and it works.

    But new problem occurs, after the phone is connected, the application stop unexpectedly. Since AVD does not support bluetooth, can you guide me on how to debug and pinpoint where might be the error?

    thanks

    • hessi

      you must use this format in server (laptop) :
      “0000110100001000800000805F9B34FB” without any dash
      and a format for client (mobile) likes this :
      “00001101-0000-1000-8000-00805F9B34FB”
      unless you encounter a message likes unfortunately your program stop

  • vijay

    code is not working ,, unable to connected any one know the idea about

  • vijay

    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;

    public ConnectThread(BluetoothDevice device)
    {
    mmDevice = device;
    BluetoothSocket tmp = null;
    Method m = null;

    try {
    //now able to connected to device ……… ////…
    m = mmDevice.getClass().getMethod(“createRfcommSocket”,
    new Class[] { int.class });

    } catch (Exception e)
    {

    System.out.println(“The Error in found….”);

    }

    try {

    tmp = (BluetoothSocket) m.invoke(mmDevice, 1);

    } catch (Exception e)
    {
    // TODO: handle exception.
    System.out.println(“The Error in found….”);

    }

    mmSocket = tmp;
    }
    i use this code for connection it working … vijay

  • Utsav

    Hey.. great project !!!

    m planning on making a bluetooth tag kind of something …which is to b controlled by a smartphone….after pairing it up with a application which is to b developed on the smartphone….if the tag is taken apart say about more than 5m from the phone….it should trigger a alarm on the phone……can u plzzz guide me on that … wat bluetooth module to b used and how can i pair it up with an android app….plzz guide !!!

  • Gursheen

    Hi Gia.. this is Gursheen from India, first of all great job buddy. its a very nice application. i need you help urgently. Currently i tested your sample code. my phone got connected with the server but no keypad was displayed on phone to operate my laptop. Im using smartphone with touch screen which has android 2.3 version. can u plz suggest me with something. need it urgently.

    • KZ

      Hi Gursheen,
      the sample have not UI implmented on it. you can control your laptop via VOLUME_UP and VOLUME_DOWN.

      • Gursheen

        Hey
        thanx for the reply. i know the above code is only for VOLUME_UP and VOLUME_DOWN but i need code for touch screen. if you could assist me to it i would be grateful to u.

        • Asma

          the same problem with me how to get input from touch keyboard , it does’t appear ! :(

  • Rajat

    Hello ,
    I can make both the codes (the client and server side) wunning successfully. but i Want to send data from my laptop and receive it on my phone .
    Can someone guide me how to do this ?
    Thanks ..

    • alex

      Hi Rajat. I was wondering if ur using a 32 or 64 bits system. cause I get native errors on 64 system. and there were supposed to be some snapshopt for 64 bits but all links are dead. If ur on 64bit too can you please let me know how you managed to get the pc server side up and running.

      Thanks,
      alex

  • Rahul Kundu

    Hi Gia
    Thank you for this nice program.
    I am facing same problem as abdo. If you got any solution please help me.
    Thanks and regards
    Rahul

    Error Details

    Exception in thread “Thread-0? java.lang.UnsatisfiedLinkError: com.intel.bluetooth.BluetoothStackToshiba.getLibraryVersion()I
    at com.intel.bluetooth.BluetoothStackToshiba.getLibraryVersion(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.setBluetoothStack(BlueCoveImpl.java:939)
    at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:482)
    at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
    at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
    at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
    at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
    at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
    at com.luugiathuy.apps.remotebluetooth.WaitThread.waitForConnection(WaitThread.java:31)
    at com.luugiathuy.apps.remotebluetooth.WaitThread.run(WaitThread.java:18)
    at java.lang.Thread.run(Unknown Source)

    • Rahul Kundu

      Hi Gia
      Problem that I mentioned in previous post has been solved. Toshiba bluetooth stack is not compatible with bluecove. So I have purchased one external bluetooth device. Now the server is working fine.
      But the mobile side is failed to discover the remote device. I am working on it. If you have any specific trick please share with us.
      Once again Thanks for the nice programme.

      • http://luugiathuy.com Gia Thuy

        Thanks for letting me know =)

  • Tom

    Great work good sir, you will go far in your career!

  • DO-IT

    hi all !
    Thank for your app
    But you can help me. I have a problem :connection = notifier.acceptAndOpen(); is not running
    I tried Leslie ‘s solution but it is not effective.
    Please ! help me
    Thanks so much

  • srk

    Actually i’m getting the following while executing the server code

    BlueCove version 2.1.0 on winsock
    0000110100001000800000805f9b34fb
    waiting for connection…

    how to give input via android phone …

  • thai_tam_2406

    Hi Gia Thuy.
    Toi co 1 cau hoi la thu vien Bluecove có ho tro dieu khien chuot tren laptop hay khong.Neu khong thi minh phai lam the nao de lam duoc dieu do.
    Cam on ban rat nhieu.
    Mong nhan duoc su tro giup cua ban trong thoi gian som nhat!

  • folp

    Hi Gia,
    Congratulations to your job!!
    Is there any restriction of the version of the android development for Bluetooth? In developer.android site indicates that it is for versions from the 11 level. Is that right?
    Thanks

  • Darlan

    Hello, As you used the java.awt with android and there is no possibility to use with android. I found some people with the same problem.

  • nonozor

    Hi !!
    Great job !
    I could make it working for android <=2.1 >=3.0
    But how can I make it works with android >2.1 and <3.0 for example for android 2.3.3 (with my Galaxy S) ??

    Thanks !
    Arno.

    • nonozor

      Finnaly I found the answer here :
      http://stackoverflow.com/questions/10315376/remote-bluetooth

      I’m very glad because I was blocking since a lot of time with this problem !

      • hessi

        Hi all… I have a problem with HTC
        this code is running on Samsong’s Android 2.3.6 easily and works very nice!,
        but it is not compatible with HTC’s Android 2.2.1… prompts the “unable to connect device” message, when i try to connect.
        i read stackoverflow but can not solve my problem.
        i was programming in netbeans with Android sdk 4.0.3
        can anyone help me ? should i change uuid ?? how ?
        thanks a lot.

      • Luciano

        can you sen me your .apk for andorid 2.3 please? luciano_crux@hot

  • Abdul Matin Muaj

    Really this is a great project.I have successfully run it.I have made exe file of desktop remoteserver but when I run it doesn’t help to connect android with my laptop.It only works why I run it by Netbeans IDE please anyone help me…………

    • Abdul Matin Muaj

      Corr: It only works when I run remoteserver by NetBeans IDE .How can I run it without IDE ?

      • Marcelo Luz

        Try to export your project as a JAR file then run it with a command line like: java -jar yourapp.jar

        • Abdul Matin Muaj

          I have made jar file of this application .I can run jar file of desktop application.Jar file of this application can be executed but immediately terminate and doesn’t recieve any command from my android.Is there any solution ?

          • http://luugiathuy.com Gia Thuy

            Hi, could you provide me any log on your java console?

          • Abdul Matin Muaj

            dear Gia Thuy will you please give jar or exe file of your desktop remoteserver ?I am using netbeans Ide here I don’t find any log

  • Adam

    Hi Gia.
    Your program rlz man:) Nice work.

    Could you help me anyway? I am student from Poland at Automatics and Robotics. I write my app in Java as a diploma and have some problems in it. If you have some time please e-mail me:
    AdamPL90@wp.pl

    Once again – good job:) Be proud of it.

  • sam

    hi,
    I want to communicate 2 android device. i have android cell phone and android tablet how i can access tablet using my cell phone,
    Scenario i want to open browser in tablet by passing command from cell phone.

    Thanks,
    Sam

  • muaz

    Hi. I got the app working on Samsung Galaxy Tab 7.0
    It can connect to the laptop, but the server on the laptop does not respond, showing “waiting for connections…”

    Is the server aware the laptop is being connected :/
    Tried putting breakpoints and found that the server stuck at
    connection = notifier.acceptAndOpen();

    Its waiting forever

    • juliano

      I’m having the same problem.. =/

  • kader

    Hi Gia,

    Really it’s a nice pg!
    I am geting an exception in compiling the server. any help would be grateful.

    kader
    —————
    Native Library intelbth_x64 not available
    Native Library bluecove_x64 not available
    Bluetooth is not turned on.
    javax.bluetooth.BluetoothStateException: BlueCove libraries not available
    at com.intel.bluetooth.BlueCoveImpl.createDetectorOnWindows(BlueCoveImpl.java:896)
    at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:439)
    at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
    at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
    at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
    at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
    at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
    at com.example.chapter7_remotebluetooth.WaitThread.waitForConnection(WaitThread.java:34)
    at com.example.chapter7_remotebluetooth.WaitThread.run(WaitThread.java:21)
    at java.lang.Thread.run(Unknown Source)
    ———-

    • http://luugiathuy.com Gia Thuy

      Hi Kader,

      You should run the program on jre 32bit. It’s because the bluecove library does not support 64bit yet. Hope it helps!

      • Luciano

        Hi Gia really nice but I have the same exception and I’m working with jre-7u7-windows-i586 32 bits?
        I don’t know what I’m doing wrong

        • Luciano

          This is what i get
          javax.bluetooth.BluetoothStateException: BlueCove native library version mismatch
          at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:454)
          at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
          at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
          at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
          at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
          at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
          at appbluetooth.WaitThread.waitForConnection(WaitThread.java:36)
          at appbluetooth.WaitThread.run(WaitThread.java:23)
          at java.lang.Thread.run(Thread.java:722)

          • http://gravatar.com/freshwake Lee

            I am getting this too.. Any solutions yet??

  • Behzad

    Hi,
    Thanks man, you are great. It helps me a lot.

  • taher

    hi i am working on bluetooth based project. i want to transmit integer data of seekbar progress value. but i am getting garbage value. please help me out

  • mike

    Hi,

    looks great! I have an application where the android is the host and remote hardware connects to it. Do I just use the accept thread and ignore the connect thread?

    I new to android!

    thanks in advance,

    mike

  • androcon

    can u help me out in doing this using Wi-Fi??? plz help

  • androcon

    plz help

  • Diego

    Hey this works great! nice job!

    I have an issue, though. When I change screen orientation on the android client, the connection gets lost. It’s strange since it doesn’t happen with the BluetoothChat sample. Does anyone know how to solve this?

    • http://gravatar.com/anasazeem Anas Azeem

      You can do two things-
      1. You can either fix the orientation of the app (to either landscape or portrait). This can be done by adding android:screenOrientation=”portrait” or android:screenOrientation=”landscape”, in that particular activity node in the AndroidManifest.xml

      2. You can override the onConfigurationChange() inside your activity. For that first you’ll have to listen to these changes by adding the following to the activity node in AndroidManifest.xml android:configChanges=”orientation”, then you can override the method and do whatever you want to do, the code in this block will be fired whenever there is an orientation change.

  • damiannelus

    As almoast everyone before, let me thank for such a great job.
    I have some troubles with connecting.

    I turn BT on both on PC and Android device.
    Devices are paired.
    Server is started with “waiting for connection…”
    I start client, establishing connection (with “connected: [PC_NAME]“).
    and that’s all. I assume, i should get “waiting for input” message, but nothing happend.

    Have you any solution or idea what’s wrong?

    Best wishes,
    Damian

  • groundman

    quiero dar las gracias por este ejemplo bluetooth. tengo un HTC ONE S android 4.0.4
    y aunque al principio no funcionaba.he cambiado el valor:

    UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);

    y va perfectamente.almenos la conexion con un modulo bluetooth.

    • olga

      hola porfa ayuda con el progra

    • AC

      Muchas gracias!
      Cambie el valor de UUID, por el q colocaste, y ahora si los puedo conectar, mas no puedo enviar mensajes aun.
      Como haces para enviar los mensajes?

  • http://member.thinkfree.com/myoffice/show.se?f=1ad6715065253a8a3d608b9b1a9037aa web ressource

    Nice blog here! Also your web site loads up very fast!
    What host are you using? Can I get your
    affiliate link to your host? I wish my website loaded
    up as fast as yours lol

  • rin

    Hi Thuy,
    your post really help me. thank you :D
    i’m a newbie in android programming and i have some question. i want to try make some button in Activity1 and Activity2, so i think method of onKeyDown must be declared in there, not in RemoteBluetooth. but it’s so disgusting if i copy all codes in RemoteBluetooth to there.
    maybe it silly question, but i really can’t think more. can RemoteBluetooth implement to Activity1 and 2? if it can, how to use?
    thank you before :D

  • Adeel Shaikh

    Hi ,
    Salute to your work, and free source code, i am trying this project with android 2.3 sdk 10 and pc, but its giving error unable to connect (Service not found), Please help me out with this error, as per my knowledge there might mis match with uuid, but i have kept the same as you have specified.

    Thanks in advance.

  • Adeel Shaikh

    Thanks a lot, it worked…….
    Changing UUID to “00001101-0000-1000-8000-00805F9B34FB” worked for me…..Thanks once again

  • Sagar

    please send me the step wise instruction to execute this project,.. its urgent!!

  • jayanth

    giving out your source code for free so that others can gain knowledge….man tis is jus an awesome gesture….hats off….great work….

  • shiv

    I’m looking for a talented developer to see if they can fix an android Bluetooth compatibility problem with a specific device. please email me for details

  • sayali

    i was trying for same application but i m not able to get the solution for uuid… I have kept it as u have specified… Please help me as early as possible..

    • outsorts

      “00001101-0000-1000-8000-00805F9B34FB”

  • Ritesh goel

    hey,i have a query…
    what i am doing is calling bluetooth intent using following code segment:

    Intent i=new Intent();
    i.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
    startActivityForResult(i,res);

    now when the user selects a paired device..it remains on same activity
    how can i return the selected device to my calling activity
    please help…

  • Sy

    How can i add bluecove.jar file to external libraries….i mean where should i add it?

  • Keny

    Hi, thank you so much. Your code help me a lot! thank you =]

  • http://gravatar.com/quaerenz quaerenz

    A mí me sirvió muchísimo, gracias!

  • Dev

    Hi,
    maybe someone knows how to control mouse using this app?

    • http://luugiathuy.com Gia Thuy

      Hi Dev,

      The robot class of Java provides functions to control mouse also.

  • http://gravatar.com/freshwake Lee

    Hello all,
    I am having troubles with the server side of the Java App. I am using a bluetooth USB to try and connect and no matter what I do it says “bluetooth is not turned on” when I can connect to the bluetooth from a phone without using the Java App.

  • http://gravatar.com/kabraadit ADIT KABRA

    can u please also give the xml code for the same?

  • Necromancer

    Can u make an app to control android music player controls like volume,stop,play,prev next from java s40 device?

  • http://www.apexengineeringproject.com yogesh

    Nice on ethank you…

  • Naveedh

    hi… thanks for ur code.. but it shows me followoing error… please help me…

    Native Library intelbth_x64 not available
    Native Library bluecove_x64 not available
    Bluetooth is not turned on
    javax.bluetooth.BluetoothStateException: BlueCove libraries not available
    at com.intel.bluetooth.BlueCoveImpl.createDetectorOnWindows(BlueCoveImpl.java:896)
    at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:439)
    at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
    at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
    at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
    at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
    at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
    at com.luugiathuy.apps.remotebluetooth.WaitThread.waitForConnection(WaitThread.java:34)
    at com.luugiathuy.apps.remotebluetooth.WaitThread.run(WaitThread.java:21)
    at java.lang.Thread.run(Unknown Source)

    • http://luugiathuy.com Gia Thuy

      Hi Naveedh, I think you have used java sdk 64. For this project, you should use the 32bits instead. Hope this helps!

    • Sumit

      while compiling and running use the d32 argument to force use the 32 bit JVM, that should help

  • https://github.com/j10mendoza/BTModuleApp Jorge

    Updated the client Android App to run on 4.2.2
    Made a quick fix by removing custom titles.

    https://github.com/j10mendoza/BTModuleApp

    • http://luugiathuy.com Gia Thuy

      Thanks for sharing Jorge! :)

  • nalqwifly

    I’ve jumped through many difficulties in order to make this code success, I was highly persistent.
    After 20 hours searching, working, debugging. Finally worked!

    A Big thanks go to you Thuy, you’re genius.

    • http://luugiathuy.com Gia Thuy

      You’re welcome! May u share with us what are your difficulties of running this code so that I can add to the instruction. Thanks!

    • Deep

      Hey nalqwifly,,would u plss upload your working code..it would help me a lot..Thnx in Adnance :-)

  • Roy

    thank u for the codes…
    can you please help me how to make a project that control a digital clock using your android phone via Bluetooth..

  • Quantm

    hey frnd..
    i m final yr CS stdnt. Nd i want to make android app which can connect 4-5 devices using bluetooth to play a game.
    Can u plz advis me abt d feasiblity as well as source code of the project..

    • oumaya

      hello ,
      i’m trying to run the RemoteBluatoothServer but i have this :
      at com.luugiathuy.apps.remotebluetooth.WaitThread.run(WaitThread.java:21)
      at java.lang.Thread.run(Thread.java:679)
      BlueCove stack shutdown completed
      plz help me to resolve this problem :’(

      • oumaya

        BlueCove version 2.1.0 on bluez
        Bluetooth is not turned on.
        javax.bluetooth.BluetoothStateException: Bluetooth Device is not ready. [1] Operation not permitted
        at com.intel.bluetooth.BluetoothStackBlueZ.nativeSetLocalDeviceDiscoverable(Native Method)
        at com.intel.bluetooth.BluetoothStackBlueZ.setLocalDeviceDiscoverable(BluetoothStackBlueZ.java:291)
        at javax.bluetooth.LocalDevice.setDiscoverable(LocalDevice.java:206)
        at com.luugiathuy.apps.remotebluetooth.WaitThread.waitForConnection(WaitThread.java:35)
        at com.luugiathuy.apps.remotebluetooth.WaitThread.run(WaitThread.java:21)
        at java.lang.Thread.run(Thread.java:679)
        BlueCove stack shutdown completed

        • Julie

          Hey!

          I got the same problem, but I read the instructions again and it says “That’s all we need for the Remote Control Server. When you run the server on a computer, make sure that the Bluetooth is ON.”

          And in the problem description there is:” Bluetooth Device is not ready. [1] Operation not permitted”

          My guess is that’s why it’s not working. ;)

  • Liang Yan

    Hi Friend,

    Really appreciate your sharing. It helps me a lot. However it cannot work in my environment.

    Could you tell me what kind of environment (Bluetooth device and Bluetooth drivers) you used ?

    I try your program in the environment in below:
    PC platform: Win7 x86
    Mobile: Android 4.1 with BlueZ (Asus A68)
    Driver: IVT Bluesoleil 2.49
    Bluetooth Device: USB bluetooth device(I do not remember the brand of it)

    Thank you in advance!!!

  • Daniel Rindt

    Hello Gia,

    i would ask if you know if the code is working properly with bluecove-2.1.1-SNAPSHOT?
    I try to get it working but without success, it looks like StreamConnectionNotifier.acceptAndOpen(); never returns anything. Simple said it is freezed. I also had no succes by sending data from the console via a connected rfcomm channel.

  • Y.S Han

    Thank you so much.
    your code is very helpful and nice!

  • Vittorino

    Hi Gia Thuy,

    I am beginner in android and i have some difficulties with Bluetooth. How about post an article Bluetooth between two Android devices?

    best regards
    Vittorino

  • aty

    hi gia thuy. i am aty from malaysia. i am a final year student from a public university and currently i am developing an app to control pc using gesture movement of smartphone and connect through Bluetooth. is it possible if you can share with me on how to develop a Bluetooth server on pc to receive the command from android phone. i hope you can contact me as soon as possible. thanks

    • http://luugiathuy.com Gia Thuy

      Hi Aty, this simple application has a Bluetooth server on pc and a Android phone client as you want.

      • deep

        Hii gia thuy..would u plss tell how to run server on pc???

        • http://luugiathuy.com/ Luu Gia Thuy

          Hi deep, you can use eclipse (https://www.eclipse.org/) to run the server on pc. Hope it helps.

  • mohammed

    hi
    in server side i have some error “The import javax.microedition cannot be resolved” how can be solve??

  • Willian Andress

    Hi, your example is very interesting, but I no understand so much, 1st.- your proyect uploaded in github, are 2 app? 1 is installed on an android device and another installed in other android device, one server and one client, Am I rigth?. Pleace I’m so sorry for the question , it’s just I’m doing my first pas.

    • http://luugiathuy.com/ Luu Gia Thuy

      Hi Willian, the RemoteBluetoothServer project is run on PC while the RemoteBluetooth is run on an Android device.

  • dnic

    hi…do bluetooth server able to send data to client?

  • Dondell Batac

    Hi there Luu Gia. i been using this example for my app to send files. But i don’t know how. Is it possible to send files like images from PC to cellphone. Thanks

  • shahryar

    Hi. i have a question from you. if i want to receive data from a non-android device over bluetooth to my android device, and show it in real-time, what should i do?