2

I want to make my android device act as input device to computers or any other devices using bluetooth hid or any profile.

As soon as i connect client device via bluetooth i should be able use my android device as mouse or keyboard just like wireless keypad or mouse.

After lot of research i come to know that android does not support HID profile so how can i achieve this is there any way to do it, I've got rooted device with me any help would be appreciated.

EDIT: computer or any other should detect android device as wireless mouse instead of detecting it as android device so that i need not install any other application in controlling side of device.

Thank you.

Newbie
  • 204
  • 1
  • 3
  • 13

1 Answers1

0

Get MAC Address (device_UUID):

InetAddress address = InetAddress.getLocalHost();
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(address);
byte[] macAddress = networkInterface.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (int byteIndex = 0; byteIndex < macAddress.length; byteIndex++) {
    sb.append(String.format("%02X", macAddress[byteIndex]));
    if((byteIndex < macAddress.length - 1)){
        sb.append("-");
    }
}

Init cmd from android, like JsonObject:

mouseMove : {"cmd" : "mouseMove", "data" : [100, 200]}
mousePress : {"cmd" : "mousePress", "data" : [100]}
keyPress : {"cmd" : "keyPress", "data" : [100]}

Create connection between two device: For Android:

BluetoothSocket socket = Device.createRfcommSocketToServiceRecord(device_UUID_PC);
socket.connect();
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
dos.writeUTF(cmdJsonObject); // for example
socket.close();

For PC:

LocalDevice localDevice = LocalDevice.getLocalDevice();
localDevice.setDiscoverable(DiscoveryAgent.GIAC); // Advertising the service
String url = "btspp://localhost:" + device_UUID_Android + ";name=BlueToothServer";
StreamConnectionNotifier server = (StreamConnectionNotifier) Connector.open(url);
StreamConnection connection = server.acceptAndOpen(); // Wait until client connects
//=== At this point, two devices should be connected ===//
DataInputStream dis = connection.openDataInputStream();

String cmdJsonObject;
while (true) {
    cmdJsonObject = dis.readUTF();
}

connection.close();

Create service using Robot execute command:

Robot robot = new Robot();
JsonObject jsonCMD = JsonObject(cmdJsonObject);
if(jsonCMD.containsKey("mouseMove")){
    JsonArray jsonData = jsonCMD.getJsonArray("data");
    int x = jsonData.getInt(0);
    int y = jsonData.getInt(1);
    robot.mouseMove(x, y);
}

I hope it can help you!

Thank @Victor Wong : Send data from android bluetooth to PC with bluecove

@Faisal Feroz : Moving the cursor in Java

Dungnbhut
  • 176
  • 5
  • Thank you for your response. whatever you suggested is i already implemented that solution but i don't want to run any other application in computer, my computer should detect android device as wireless mouse instead of detecting it as android device. – Newbie Oct 12 '17 at 08:40
  • Oh my god! That's impossible – Dungnbhut Oct 12 '17 at 09:02
  • It is possible by interacting with drivers. – Newbie Oct 12 '17 at 09:04