Re: How to use Android as a HID device(Mouse/Keyboard/gamepad) using Bluetooth HID Profile for connect to PC/XBox/Wii ?

19,595 views
Skip to first unread message

Jayantakumar Singh Konjengbam

unread,
May 6, 2013, 12:31:57 PM5/6/13
to android-...@googlegroups.com
It appears you are novice in Bluetooth technology and the related protocol stacks. For your need, you should be focusing on custom Android Firmware, with your HID/input driver changes (most likely at the Linux kernel level). Please read more of HID profile specs and check your feasibility. 

Regards, 
Jayanta 

Sent from my BlackBerry® PlayBook™
www.blackberry.com


From: "gihan karunarathne" <gckarun...@gmail.com>
To: "android-...@googlegroups.com" <android-...@googlegroups.com>
Sent: 6 May, 2013 10:28 AM
Subject: How to use Android as a HID device(Mouse/Keyboard/gamepad) using Bluetooth HID Profile for connect to PC/XBox/Wii ?

Hi Android Devs:

I'm currently contributing to an Open Source project. So, we are planning to improve it as a Wireless Human Interface Device (gamepad, mouse, keyboard) for PCs and XBox, Wii, Playstation etc. After implementing those functionality, users can create a device (mouse, keyboard) on top of our application and can use them as a remote to control PC etc.

Problems come with Usability aspects:
But our main targeted users are kids. Hence we more consider about Usability. Thus we are willing to implement those functionality in Android as a HID device. Which means, without having a application running on PC side(like send data via Bluetooth RFCOMM and trigger those events using PC side application), want to automatically detect Android device as a HID mouse/keyboard via Bluetooth HID profile. I know, this is some thing out of the scope of mobile platform's aspects. But please be kind enough to give some attention.

Questions:
Android provides RFCOMM protocol  and few other Bluetooth profiles (but in system level it has mandatory protocols like LMP,L2CAP and SDP in it's Bluetooth protocol stack). Also it doesn't give permission to add entries to the Service Discovery Protocol (SDP) and doesn't provide any functionality for the L2CAP Bluetooth protocol which is required for implement the Bluetooth HID profile. In order to detect Android as a HID by PC or other devices, we have to register service in SDP to discovered by other devices as far as I know.
(I attached a detailed problem description below what I came up after doing some researches if you are interesting.)

#. Please, correct me if I'm wrong.
#. Is it possible to use Android device as a HID device(mouse/keyboard/gamepad) by using Bluetooth HID profile to the PC? Can you give me more resources ?

Any comments about this issue will help me lots. Thank you in advance !.

--Cheers
Gihan Karunarathne


P.S. 
Detailed Problem Description
    I researched about how to do it with Android device without using a PC side application. Bluetooth is using different type of protocols to communicate in short range devices. Bluetooth protocol stack is split as "controller stack" dealing with physical layer for send data and "host stack" dealing with high level data[0] [1]. In generic implementation host stack is a part of the OS. For devices like Bluetooth headsets and keyboards, host stack features are embedded with controller stack. According to the protocol stack [2], L2CAP protocol directly call to HCI and access controller stack. On top of that, SDP (service discovery protocol) allow devices to discover what services each other support (It has a list of supporting Bluetooth profiles [3] which are resides on top of the Bluetooth Core).
     According to the Wiki page, the mandatory protocols are LMP,L2CAP and SDP. Android Bluetooth support wasn't a much matured one as mentioned in many forums and it implemented above protocols, but Android SDK doesn't give permission to add entries to the SDP and doesn't provide any functionality for the L2CAP Bluetooth protocol which is required for implement the Bluetooth HID profile. A Bluetooth HID implementation for Android  called "Androhid"[4] also suffer from those issues. I also tries with few Android apps those are supported HID(Bluetooth Keyboard Easyconnect, BlueputDroid), but they also suffer from same fact.
     Also Android provide mandatory RFCOMM protocol API and few other Bluetooth profiles [5] [6], but not HID profile. Other Android apps (Unified Remote, Ultimate Gamepad) are using PC side application (Most of them are using BlueCove java library to get the cross platform support) as a receiver to trigger events.
[0]. http://en.wikipedia.org/wiki/Bluetooth#Technical_information
[1]. http://en.wikipedia.org/wiki/Bluetooth_protocols
[2]. http://www.developer.nokia.com/Community/Wiki/images/e/ef/Protocol_stack.png?20070412054824 Bluetooth Protocol Stack
[3]. http://en.wikipedia.org/wiki/Bluetooth_profile
[4]. https://code.google.com/p/androhid/wiki/FAQ AndroHID
[5]. http://developer.android.com/guide/topics/connectivity/bluetooth.html
[6]. http://developer.android.com/reference/android/bluetooth/package-summary.html

-- 
Regards
Gihan Chanuka Karunarathne
Undergraduate of Department of Computer Science and Engineering
University of Moratuwa
Sri Lanka

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-platform?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ime priimek

unread,
Jun 18, 2013, 7:35:04 PM6/18/13
to android-...@googlegroups.com
Hi Gihan,

There is a solution available for your problem. Your Android device can act as HID device without actually having HID bluetooth profile and you don't need to root it to achieve this. You need to have a dedicated USB dongle which handles also "protocol conversion". So, to the PC it looks like ordinary HID keyboard/mouse and to the Android device it looks like SPP-profile bluetooth device.
This is the only feasible approach known to me that you don't have to install anything on the PC and that any non-rooted Android 2.0 or later device with bluetooth present is supported.

Check this interesting presentation video with several use cases shown: http://youtu.be/lawrKeaO5rk

On the vendor's web page there is also documentation available targeting developers like you.


BTW: The video is part of Indiegogo campaign, direct link to it is:
http://www.indiegogo.com/at/hiDBLUE


Regards,  Ivan.

Jayantakumar Singh Konjengbam

unread,
Jun 19, 2013, 12:33:16 PM6/19/13
to android-...@googlegroups.com

The solution proposed is not deriving a solution out of Android but using a ready-made HID compliant USB stick and render any USB hub supported device the needed Bluetooth capability.

For this non-coding activity, anyone can buy those Bluetooth dongles (with HID profile) from big names like Broadcom/CSR etc.? Those dongles would anyway come already pre-qualified with all the necessary tests etc.

 

Just a thought.

 

Regards,

Jayanta K.

--

You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.

hamish S

unread,
Aug 25, 2013, 7:14:02 PM8/25/13
to android-...@googlegroups.com
Hello,

There is this, but it's for a rooted phone:

Not like rooting is a big deal though . . .

Abner Chou

unread,
Feb 12, 2014, 3:26:35 PM2/12/14
to android-...@googlegroups.com
Have you figure out a way to solve this problem? I'm also encountered similar problem on my little project.

Thanks

Kamal Raghav

unread,
Mar 20, 2014, 12:51:07 AM3/20/14
to android-...@googlegroups.com
Hi gihan,

I also had the simillar project in my mind. This is when i tried to search google developers site for available profile options for BT. But the HID class profile is blocked.
The questions we need to address are
1. Adding the HID profile interface from the kernel source, i.e. BT stack given for the device. 
this might be possible most likely with Nexus phones, if the source code is available on the git server for the kernel build.
once this is available, we need to create AIDL and C++ or Java interface for adding this profile or supporting the same along with A2DP or L2CAP.
This will be in the framework side.
2. Creating the app which will interface with your accelerometer and gyro and then convert the data to suitable mose events.
   i.e. EVENT_RELATIVE values via the HID interface over BT.

I too wanted to work on the same, and have a cubie truck board, but not able to find proper source code that builds the support link is broken from sunxi website. :(

Regards,
Kamal

Supritha patil

unread,
Nov 30, 2014, 11:55:33 PM11/30/14
to android-...@googlegroups.com

sir, 
I have read your post.
I'm working on this,not getting how to trigger an event from PC to mobile via Bluetooth.

Kamal Raghav

unread,
Dec 3, 2014, 2:35:51 AM12/3/14
to android-...@googlegroups.com
I guess you need to write an application in android.

1. create a connection/pairing app in android using the Bluetooth as interface.
   a. you can create a serial interface over bluetooth
   b. you can create a network interface over bluetooth
2. design your own protocol for communication using this interface, i.e.
   a. create a struct to encapsulate your data or commands 
   b. based on the commands received, trigger an intent in the android device
3. write an application in C or Java in PC for communicating with your android device
   a. design your own signature for the device to attach using the bluetooth serial/network interface
       i.e. it could be your name passed in the serial packet that the android device could use to continue with commands.

Please let me know if you have any issues in the given steps.
Once this is done you can take it further to add more commands, just try triggering camera app and closing it.

Regards,
Kamal Raghav

--
You received this message because you are subscribed to a topic in the Google Groups "android-platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-platform/8Re-DxeOj54/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-platfo...@googlegroups.com.

To post to this group, send email to android-...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

Kamal Raghav

unread,
Dec 3, 2014, 7:48:01 AM12/3/14
to android-...@googlegroups.com
Hi supritha,

Just found a link to start off with your stuff.

Is there any specific module where you are struck? if so please share it, so that i can look into it and suggest a way around.

Regards,
Kamal

Supritha patil

unread,
Dec 5, 2014, 1:13:02 AM12/5/14
to android-...@googlegroups.com
Thank you for your reply,

yes i have my application in android but i am not getting how to go further.as you told need to write an application in C or java i need one clarification that is it possible to write an application in javascript?.

shridutt kothari

unread,
Dec 5, 2014, 4:23:47 AM12/5/14
to android-...@googlegroups.com
No, for such kind of functionality can't be implemented using Javascript in Android.

You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.

To post to this group, send email to android-...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards,
Shridutt Kothari.

Supritha patil

unread,
Dec 5, 2014, 10:20:58 AM12/5/14
to android-...@googlegroups.com
I am very new to this android.i have done a android application with on/off/sacn/pair/camera button in that application.is it right that what i have done till now?if it is right please tell me the next step.

ch...@christopherprice.net

unread,
Dec 8, 2014, 7:55:46 AM12/8/14
to android-...@googlegroups.com
I'll admit my team has thought about this one for awhile. Our team's assessment was to do this properly, you would need to write a Bluedroid system driver that adds Bluetooth HID. You could alternatively write an application that tries to announce BT HID via Bluetooth SPP profiles, but this becomes complicated and would likely require as much effort on the client as a Wi-Fi driver app.

The only way to rule out per-vendor or custom firmware, would be to commit it to AOSP. Then all devices would have it at the next major Android release.

I agree it would be nice for Bluetooth HID server to be part of Android, and it would be a key differentiator seeing as Windows Phone and iOS don't even support mouse client today.

This could then be toggled on in Bluetooth settings, and enabling the feature in Bluetooth settings would also add a keyboard/mouse server all to the list of available apps. When paired with a device, launching the input app from Launcher would then allow the Android to act as an input device for the client.

This is one of those things were it would be great to hear if there's interest from AOSP in terms of inclusion - Kickstarter and other projects could fund this kind of R&D, but it's hard to get community funding if there's a lack of assurance Google would even take up the commits.

Christopher Price

Kamal Raghav

unread,
Dec 17, 2014, 11:24:01 AM12/17/14
to android-...@googlegroups.com
Hi Chris,

I was also looking for update on similar kind, but as you said Android currently does not support HID interface and many other features.
That the reason i had suggested for Bluetooth socket connection. My idea of the app is given below, please feel free to correct me if i go wrong.

1. create a bluetooth socket from Android device using RFCOM service available
public BluetoothServerSocket listenUsingRfcommWithServiceRecord (String name, UUID uuid)

2. Try to get the pairing from the desktop using any open bluetooth s/w for windows or linux

3. Design your own protocol to support bidirectional data flow (or you could re-use part of existing mouse driver code in linux),.
    once paired with the desktop you can send some data to/from android device using the rf socket created above.

If you want to create an app to be used as mouse on desktop, i would suggest using the linux platform and writing your own "input subsystem" driver as a sample mouse device.
Once the mouse driver is inserted, use your communicating app to receive commands(raw data) from android device.
The app should have the mouse driver opened and insert the corresponding commands, such as movement or mouse click into the input stream.

If you want to use your desktop to control the android mouse on android device, it would be little complicated as this will be only for your device.
You need to tap into the touch driver on android and insert the corresponding movement and click commands manually.
Else you would have to write an app that works in the background and using the rf socket converts raw data form desktop to input framework events.

@ supritha
If you have still further doubts on my approach, do let me know.

Regards,
Kamal

Luca Palmieri

unread,
Dec 22, 2014, 12:20:00 PM12/22/14
to android-...@googlegroups.com
Hi Kamal,
I'm interesting in what you explained just above. We were thinking of developing an application (for Android) with almost same characteristic as you mentioned above, and we arrived to the same conclusion that the easiest way to start was to create our own driver for Linux OS (now reading the book for Linux Device Drivers).
What I would like to ask you is exactly how to implement (or include) a driver inside an Android application (never done before) if you could give me some more detailed explanation it would be awesome.
And also I have a little bit of confusion in the initial steps that we should plan: before we need a pairing between device and PC, and then we can use our drivers and let the PC see our device as a mouse?

Thank you very much in advance,
Best regards
Luca

Kamal Raghav

unread,
Jan 7, 2015, 10:19:04 AM1/7/15
to android-...@googlegroups.com
Hi Luca,

If am assuming correctly, you are trying to move mouse on PC using android device.
If so, You dont need to push in your driver in android.
Basic pairing API's for socket communication over serial line is present in android framework.
Just use those to write an android app for creating socket with your paired device.

Once the pairing is done then you can define your own communication standard/protocol to interpret the raw data.

Else if you want to implement keyboard and mouse profile 
Once you download the android code, you need to sneak in your own driver by creating a input driver(for this there are good samples, else you could refer to essential linux device driver book chapter on input device's) .
You need to write an interface user-space app/driver running in background which does the pairing for you and receives and interprets raw data from paired PC for you. 

You need to write the glue logic in android interface layer(majorly C++ framework) with minimal functionality such as scan, pair, transfer and so on.

Regards,
Kamal

Young-Ho Cha

unread,
Jan 7, 2015, 11:06:10 AM1/7/15
to android-...@googlegroups.com
To implement Bluetooth HID, it need to create L2CAP socket.

But Android SDK did not allow that an application create L2CAP socket.

L2CAP socket can create only android.bluetooth package.



2013년 5월 6일 월요일 오후 5시 21분 51초 UTC+9, gihan karunarathne 님의 말:

Supritha patil

unread,
Jan 15, 2015, 12:48:07 AM1/15/15
to android-...@googlegroups.com
Is it possible to share the image to destination Bluetooth address directly from just like Bluetooth chat application in android to transfer a text.

--

Luca Palmieri

unread,
Jan 15, 2015, 4:57:06 PM1/15/15
to android-...@googlegroups.com
Hi Kamal,

First of all thanks for your answer. You're assuming correctly, that's exactly what we are trying to do. 
I'm glad to hear that seems to be possible what we are planning, I just would like to ask you some more detailed question! 

- When you say we don't need to push the driver in android, you mean we can just pair the device with the computer and then use a socket and be able to move the pointer on the pc (implementing our communication standard)? But this would imply to define the communication standard on the pc, right? And our goal is to be able to move the pointer without installing software (or defining protocols) on PC. (tell me if I'm wrong)

- So the second plan seems more complicate, but more focused to the point. What you are suggesting is to have an application that implement the android bluetooth profile and that has a driver inside, and we build like a sort of "bridge" (the glue logic) in order to be able to pass from the user interface (our application on the phone) to the driver and the data transmission via bluetooth? (is that what you were saying). 

It's the first time implementing a driver, so this could be a little bit tricky, so it would be awesome if I could bother you with some other technical question (if I understood correctly what you told me, I think we would follow the second way and implement the profile) and enter more in detail on the architecture of the above explained application

Really thankful for your answer
Regards,
Luca

Kamal Raghav

unread,
Jan 16, 2015, 7:45:10 AM1/16/15
to android-...@googlegroups.com
Hi Luca,

Yes, the first approach is a hack or work around for the solution.

For the second approach your would require BlueTooth HID documentation could be openly available if it is older one. Else you need to be a member of the SIG(special interest group) for latest specs.
Secondly you would need to write the Bluetooth HID client driver interface for mouse and keyboard. It is likely that it could be borrowed from opensource code or need to be written entirely. You could follow the bluetooth driver code available in the android source pulled in. It would be great if you have kernel source within android build setup. This would most likely be available for base boards such as beagleboard or need to specifically get the git repo from the board vendors. 
From there you need to move up in interweaving the HID driver along the Bluetooth framework in the rest of the android repository.
The ideal place to start from is the make files in the android product folders
such as android.mk and look up how the bluetooth framework is built up.
Here in the bluetooth java codes you might need to write code for creating a service running in the background.

Regards,
Kamal

mruthyunjay pattanshetti

unread,
Oct 11, 2017, 12:57:11 PM10/11/17
to android-platform

Hi i am looking for same kind of project development but androidhid crashes whenever i launch application, my device is rooted also.
You have any suggestion on this issue? 
Reply all
Reply to author
Forward
0 new messages