0

我想让我的android设备充当电脑或任何其他使用蓝牙隐藏或任何配置文件的设备的输入设备。如何在android中使用蓝牙HID配置文件?

只要我通过蓝牙连接客户端设备,我应该可以使用我的android设备作为鼠标或键盘,就像无线键盘或鼠标一样。

经过大量的研究,我才知道android不支持HID配置文件,所以我如何才能做到这一点,有没有办法做到这一点,我有任何帮助的根源设备将不胜感激。

编辑:电脑或任何其他应该检测到Android设备作为无线鼠标,而不是检测到它为Android设备,以便我不需要安装任何其他应用程序控制设备的一面。

谢谢。

回答

0

获取MAC地址(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("-"); 
    } 
} 

从机器人初始化CMD,像的JSONObject:

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

创建连接之间的两个装置: 对于机器人:

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

对于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(); 

使用机器人执行命令来创建服务:

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); 
} 

我希望它可以帮助你!

感谢 @Victor黄:Send data from android bluetooth to PC with bluecove

@Faisal FEROZ:Moving the cursor in Java

+0

谢谢您的答复。无论你的建议是我已经实施该解决方案,但我不想在计算机上运行任何其他应用程序,我的电脑应该检测Android设备作为无线鼠标,而不是将其检测为Android设备。 – Newbie

+0

天啊!这是不可能的 – Dungnbhut

+0

这是可能的与司机交互。 – Newbie