Android的蓝牙连接其他蓝牙设备 [英] Android Bluetooth to connect another bluetooth device
问题描述
Im做基于蓝牙的应用程序,我想连接其他设备,如诺基亚设备和打印机。
Im doing bluetooth based application, I want to connect other devices like nokia devices, and printer.
我指的是Android的蓝牙文件 http://developer.android.com/导/主题/连接/ bluetooth.html 。它演示了所有基本的蓝牙API capabilites,而我做这所有的事情
I refer the android bluetooth documentation http://developer.android.com/guide/topics/connectivity/bluetooth.html. It demonstrates all the fundamental Bluetooth API capabilites, And I did these all the things
Scanning for other Bluetooth devices
Querying the local Bluetooth adapter for paired Bluetooth devices
Establishing RFCOMM channels/sockets
Connecting to a remote device
Transfering data over Bluetooth
我得到借鉴BluetoothChat,Android的样本。
i get reference from BluetoothChat, samples of android.
BluetoothChat This application send data to another android device but for that this application must be installed in both the devices.
像这样<一个href="http://stackoverflow.com/questions/6227498/how-to-send-file-from-android-device-to-other-device-through-bluetooth-by-$c$c">How通过蓝牙由code 从Android设备发送文件到其它设备
Like this How to send file from Android device to other device through Bluetooth by code
我要的是
- 我想从一个设备从我的应用程序发送文件到另一台设备,而且也适用甚至是另一个不运行我们的应用程序的设备。即接收设备还能够使用默认的蓝牙接收文件。
这是可能的机器人?
推荐答案
您可以轻松地做两BT的设备之间的连接。 你只需要调用
You can do connection between two BT devices easily. You just need to call
createRfcommSocketToServiceRecord(UUID)
与UUID的理解接收装置。 对于文件传输操作的UUID必须等于(举例)00001106-0000-1000-8000-00805F9B34FB(文件传输服务)
with UUID that understand receiver device. For file transfer action UUID must be equal (for example) to 00001106-0000-1000-8000-00805F9B34FB (File transfer service)
所以,你的连接code威力看起来像下面
So you connection code might looks like code below
BluetoothDevice类设备= mBluetoothAdapter.getRemoteDevice(00:0A:94:16:77:A0); 的BluetoothSocket ClientSocket的;
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("00:0A:94:16:77:A0"); BluetoothSocket clientSocket;
try {
log(TAG, "Remote device " + device);
ParcelUuid[] uuids = device.getUuids();
boolean isFileTransferSupported = false;
UUID ftpUID = UUID.fromString("00001106-0000-1000-8000-00805F9B34FB");
// Check if remote device supports file transfer
for (ParcelUuid parcelUuid: uuids) {
if (parcelUuid.getUuid().equals(ftpUID)) {
isFileTransferSupported = true;
break;
}
}
if (!isFileTransferSupported) {
log(TAG, "Remote bluetooth device does not supports file transfer ");
return;
}
clientSocket = device.createRfcommSocketToServiceRecord(ftpUID);
clientSocket.connect();
} catch (IOException e) {
return;
}
这篇关于Android的蓝牙连接其他蓝牙设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!