1

我正在尝试在 Android (GT-I5700 上的 2.1-update1)手机上打开蓝牙服务器套接字,但它失败了。我已经没有想法了。欢迎对我所缺少的内容提出一些建议。蓝牙已打开,所以这应该不是问题。

我也很确定权限没问题:

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

失败的代码非常简单:

String TAG = "MYAPP";
UUID UUID_RFCOMM_GENERIC = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothSocket s;
BluetoothServerSocket bss;
try {
    Log.i(TAG, "We do reach this point");
    bss = adapter.listenUsingRfcommWithServiceRecord("PrettyService", UUID_RFCOMM_GENERIC); 
    Log.i(TAG, "We never reach this");
    s = bss.accept();
} catch (IOException e) {
    Log.i(TAG, "Blutooth failed");
}

和日志:

INFO/MYAPP(9087): We do reach this point
DEBUG/BluetoothSocket(9087): BluetoothSocket created fd: -1uuidnullport 1
DEBUG/BluetoothSocket.cpp(9087): initSocketNative
INFO/BLZ20_WRAPPER(9087): blz20_wrp_socket: fam 31, type 1, prot BTPROTO_RFCOMM
DEBUG/BLZ20_WRAPPER(9087): blz20_init: initializing...
DEBUG/BTL_IFC_WRP(9087): wsactive_init: init active list
INFO/BTL_IFC(9087): main_client_thread: Client main thread starting
DEBUG/BLZ20_WRAPPER(9087): blz20_init: success
INFO/BTL_IFC(9087): BTL_IFC_RegisterSubSystem: Register subsystem [(null)]
INFO/BTL_IFC(9087): btl_ifc_ctrl_connect: Connect control channel for subsystem [(null)]
DEBUG/BTL_IFC_WRP(9087): wrp_sock_create: CTRL
DEBUG/BTL_IFC_WRP(9087): wrp_alloc_new_sock: wrp_alloc_new_sock sub 1
ERROR/BTL_IFC_WRP(9087): ##### ERROR : wrp_sock_create: socket create failed (Permission denied)#####
DEBUG/BTL_IFC_WRP(9087): wrp_sock_create: -1
DEBUG/BluetoothSocket.cpp(9087): socket() failed, throwing
INFO/MYAPP(9087): Blutooth failed

这个错误非常难看,谷歌搜索什么也没有。我对整个 Android 世界也很陌生。

4

0 回答 0