用于与arduino进行蓝牙通信的Android应用程序

时间:2013-04-27 21:49:39

标签: android

我需要通过蓝牙通信向我的PC发送字符串来测试我的android程序。

我发现这个应用程序确实将字符串发送到arduino

http://www.elecfreaks.com/829.html

我可以使用此应用程序将字符串发送到我的电脑而不使用arduino吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以创建一个Java应用程序作为蓝牙服务器,并使用它来测试蓝牙客户端应用程序。

为此,您需要Bluecove library,这是一个示例代码段:

UUID serialUUID = new UUID("1101", true);
String SERVICE_URL = "btspp://localhost:" + serialUUID
        + ";name=My Bluetooth Server;authorize=false;authenticate=false";

StreamConnectionNotifier connectionNotifier = 
                          (StreamConnectionNotifier) Connector.open(SERVICE_URL);

System.out.println("Server is waiting for client ... \n URL=" + SERVICE_URL);

// Wait until client connects i.e. a blocking method
StreamConnection connection = connectionNotifier.acceptAndOpen();

RemoteDevice remoteDevice = RemoteDevice.getRemoteDevice(connection);
System.out.println("Client connected: "+remoteDevice.getBluetoothAddress());

// Communicate with the device using the below I/O streams
InputStream iStream = connection.openInputStream();
OutputStream oStream = connection.openOutputStream();