Android的蓝牙COM端口 [英] Android Bluetooth COM port

查看:252
本文介绍了Android的蓝牙COM端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了一些时间研究Android的使用,旨在通过蓝牙COM端口的PC上进行通信的蓝牙设备进行通信的能力。我一直没能找到一个明确的答案,所以我想我会问这里。我要确保这是可能与Android。

I have spent some time researching Android's ability to communicate with bluetooth devices that are designed to communicate over a Bluetooth COM port on a PC. I haven't been able to find a definitive answer, so I thought I'd ask here. I want to make sure that this is possible with Android.

我是新来的蓝牙通信,但我迄今所做的研究使我RFCOMM这在一定程度听起来像我想要的东西。不幸的是,我还无法确认这是事实可能。

I am new to Bluetooth communications, but the research I've done so far lead me to RFCOMM which somewhat sounded like what I wanted. Unfortunately, I'm still unable to confirm that this is in fact possible.

任何帮助/资源将大大AP preciated。

Any help/resources on this would be greatly appreciated.

推荐答案

是的,Android的可以连接到PC上的蓝牙COM端口。我目前正在开发这样的应用程序。这里是一个code例子(ITE需要蓝牙权限TE在Manifest.xml文件中设置):

Yes, Android can connect to Bluetooth COM ports on PC's. I am currently developing such an application. Here is a code example (Ite requires the bluetooth permissions te be set in the Manifest.xml file):

<uses-permission android:name="android.permission.BLUETOOTH" />

Java的:

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) {
    // Device does not support Bluetooth
    finish(); //exit
}

if (!adapter.isEnabled()) {
//make sure the device's bluetooth is enabled
    Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBluetooth, REQUEST_ENABLE_BT);
}

final UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); //UUID for serial connection
mac = "00:15:83:3D:0A:57"; //my laptop's mac adress
device = adapter.getRemoteDevice(mac); //get remote device by mac, we assume these two devices are already paired


 // Get a BluetoothSocket to connect with the given BluetoothDevice
BluetoothSocket socket = null;
OutputStream out = null;
try {
    socket = device.createRfcommSocketToServiceRecord(SERIAL_UUID); 
} catch (IOException e) {}

try {           
    socket.connect(); 
    out = socket.getOutputStream();
    //now you can use out to send output via out.write
} catch (IOException e) {}

这篇关于Android的蓝牙COM端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆