2012-12-17 168 views
4

我在做基于蓝牙的应用程序,我想连接其他设备,如诺基亚设备和打印机。Android蓝牙连接另一个蓝牙设备

我参考了android蓝牙文档http://developer.android.com/guide/topics/connectivity/bluetooth.html。它演示了所有基本的蓝牙API功能,并且我做了所有这些事情。我从BluetoothChat获得了Android的示例的引用。

BluetoothChat This application send data to another android device but for that this application must be installed in both the devices. 

喜欢这个How to send file from Android device to other device through Bluetooth by code

我想是

  1. 我想从一个设备从我的应用程序发送文件到另一台设备,并且也适用不运行我们的应用程序甚至其他设备。即Receiver设备也能够使用默认蓝牙接收文件。

这是可能的android?

回答

0

我认为这是不可能的。

其实,当你创建一个蓝牙套接字,你必须使用createRfcommSocketToServiceRecord(UUID)

此功能需要一个UUID是两个设备上的应用程序之间共享,因此可以建立连接字符串。

如果没有蓝牙套接字在另一台设备上侦听,使用完全相同的UUID,您将无法共享数据。

+0

感谢您的回复,我想明确的是,有没有办法通过我的应用程序中的编码到蓝牙设备连接?或者有任何解决方法? –

0

您可以轻松地在两台BT设备之间进行连接。 你只需要调用

createRfcommSocketToServiceRecord(UUID) 

与UUID说明白接收器设备。 对于文件传输操作UUID必须是(例如)等于00001106-0000-1000-8000-00805F9B34FB(文件传输服务)

所以你的连接代码可能看起来像下面

BluetoothDevice类设备= 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; 
} 
+0

嘿你找到了解决方案? – abhishek