android 拒绝打开蓝牙,Android蓝牙IOException:连接被拒绝

我正在尝试连接蓝牙RFCOMM设备。我使用sl4a并从Python脚本连接。我有两个Android设备运行相同的Android版本2.3.4。

在一台设备上(Galaxy S2具有非常接近库存的内核,root),脚本运行正常并连接到RFCOMM设备。在另一台设备上,一个充满异国情调的Winmate E430T(专业坚固的Android手机,我怀疑它的体积很小),我得到了java.io.IOException: Connection refused。

我尝试运行示例代码bluetooth_chat.py但没有成功,那个用于Android到Android的连接。我收到相同的错误消息,这表明问题不在我的代码中,而是更多Winmate手机的状态(root或不,已安装SW,配置)。

有人见过类似的东西吗?我看到关于unpair-repair的帖子,我尝试了两次,但没有帮助。我还尝试在安装Python和所有模块后重新启动Winmate。

代码:

import android

droid = android.Android()

address = '00:12:F3:11:DC:D5'

uuid = '00001101-0000-1000-8000-00805F9B34FB'

droid.toggleBluetoothState(True)

droid.bluetoothConnect(uuid, address)

logcat的摘录:

V/sl4a.JsonRpcServer:117(27913): Sent: {"error":null,"id":6,"result":{"which":"negative"}}

V/sl4a.JsonRpcServer:74(27913): Received: {"params": [], "id": 7, "method": "bluetoothConnect"}

I/ActivityManager( 1304): Starting: Intent { flg=0x18000000 cmp=com.googlecode.android_scripting/.activity.FutureActivity (has extras) } from pid 27913

I/HK/LatinKeyboardBaseView( 1385): closing org.pocketworkstation.pckeyboard.LatinKeyboardView@407d4810

D/sl4a.ConsoleActivity:761(27913): onResume called

D/sl4a.ConsoleActivity:746(27913): onPause called

V/sl4a.FutureActivity:50(27913): FutureActivity created.

I/ActivityManager( 1304): Starting: Intent { cmp=com.googlecode.android_scripting/.activity.BluetoothDeviceList } from pid 27913

E/BluetoothEventLoop.cpp( 1304): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/23550/hci0

V/BluetoothEventRedirector( 1862): Received android.bluetooth.adapter.action.DISCOVERY_STARTED

I/HK/LatinKeyboardBaseView( 1385): closing org.pocketworkstation.pckeyboard.LatinKeyboardView@407d4810

E/BluetoothEventLoop.cpp( 1304): event_filter: Received signal org.bluez.Adapter:DeviceFound from /org/bluez/23550/hci0

D/BluetoothService( 1304): updateDeviceServiceChannelCache(00:12:F3:11:DC:D5)

V/BluetoothEventRedirector( 1862): Received android.bluetooth.device.action.FOUND

E/BluetoothEventLoop.cpp( 1304): event_filter: Received signal org.bluez.Adapter:DeviceFound from /org/bluez/23550/hci0

D/BluetoothService( 1304): updateDeviceServiceChannelCache(0C:DF:A4:78:99:50)

I/ActivityManager( 1304): Displayed com.googlecode.android_scripting/.activity.BluetoothDeviceList: +449ms (total +519ms)

D/BluetoothService( 1304): uuid(system): 00001105-0000-1000-8000-00805f9b34fb 3

V/BluetoothEventRedirector( 1862): Received android.bluetooth.device.action.FOUND

D/wpa_supplicant(19159): CMD: DRIVER RSSI-APPROX

D/wpa_supplicant(19159): wpa_driver_tista_driver_cmd RSSI-APPROX

D/wpa_supplicant(19159): rssi-approx command

D/wpa_supplicant(19159): CMD: DRIVER LINKSPEED

D/wpa_supplicant(19159): wpa_driver_tista_driver_cmd LINKSPEED

D/wpa_supplicant(19159): Link Speed command

D/wpa_supplicant(19159): buf LinkSpeed 54

E/BluetoothEventLoop.cpp( 1304): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/23550/hci0

E/BluetoothService.cpp( 1304): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)

V/BluetoothEventRedirector( 1862): Received android.bluetooth.adapter.action.DISCOVERY_FINISHED

D/sl4a.ConsoleActivity$1:145(27913): Connected to TerminalManager and found bridges.size=1

I/HK/LatinKeyboardBaseView( 1385): closing org.pocketworkstation.pckeyboard.LatinKeyboardView@407d4810

D/sl4a.ConsoleActivity:761(27913): onResume called

E/BluetoothEventLoop.cpp( 1304): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/23550/hci0/dev_0C_DF_A4_78_99_50

D/BluetoothService( 1304): updateDeviceServiceChannelCache(0C:DF:A4:78:99:50)

D/BluetoothService( 1304): uuid(system): 00001105-0000-1000-8000-00805f9b34fb 3

D/BluetoothService( 1304): uuid(application): 457807c0-4897-11df-9879-0800200c9a66 13

D/BluetoothService( 1304): Making callback for 457807c0-4897-11df-9879-0800200c9a66 with result 13

V/BluetoothEventRedirector( 1862): Received android.bleutooth.device.action.UUID

E/sl4a.JsonRpcServer:101(27913): Invocation error.

E/sl4a.JsonRpcServer:101(27913): java.io.IOException: Connection refused

E/sl4a.JsonRpcServer:101(27913): at android.bluetooth.BluetoothSocket.connectNative(Native Method)

E/sl4a.JsonRpcServer:101(27913): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:204)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.facade.BluetoothFacade.bluetoothConnect(BluetoothFacade.java:158)

E/sl4a.JsonRpcServer:101(27913): at java.lang.reflect.Method.invokeNative(Native Method)

E/sl4a.JsonRpcServer:101(27913): at java.lang.reflect.Method.invoke(Method.java:507)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.jsonrpc.RpcReceiverManager.invoke(RpcReceiverManager.java:87)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.facade.FacadeManager.invoke(FacadeManager.java:58)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.rpc.MethodDescriptor.invoke(MethodDescriptor.java:109)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.jsonrpc.JsonRpcServer.handleConnection(JsonRpcServer.java:99)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.SimpleServer$ConnectionThread.run(SimpleServer.java:91)

V/sl4a.JsonRpcServer:117(27913): Sent: {"error":"java.io.IOException: Connection refused","id":7,"result":null}

V/sl4a.JsonRpcServer:74(27913): Received: {"params": [], "id": 8, "method": "bluetoothReadLine"}

E/sl4a.JsonRpcServer:101(27913): Invocation error.

E/sl4a.JsonRpcServer:101(27913): java.io.IOException: Bluetooth not ready for this connID.

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.facade.BluetoothFacade.getConnection(BluetoothFacade.java:95)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.facade.BluetoothFacade.bluetoothReadLine(BluetoothFacade.java:231)

E/sl4a.JsonRpcServer:101(27913): at java.lang.reflect.Method.invokeNative(Native Method)

E/sl4a.JsonRpcServer:101(27913): at java.lang.reflect.Method.invoke(Method.java:507)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.jsonrpc.RpcReceiverManager.invoke(RpcReceiverManager.java:87)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.facade.FacadeManager.invoke(FacadeManager.java:58)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.rpc.MethodDescriptor.invoke(MethodDescriptor.java:109)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.jsonrpc.JsonRpcServer.handleConnection(JsonRpcServer.java:99)

E/sl4a.JsonRpcServer:101(27913): at com.googlecode.android_scripting.SimpleServer$ConnectionThread.run(SimpleServer.java:91)

V/sl4a.JsonRpcServer:117(27913): Sent: {"error":"java.io.IOException: Bluetooth not ready for this connID.","id":8,"result":null}

V/sl4a.JsonRpcServer:74(27913): Received: {"params": ["Chat Received", null], "id": 9, "method": "dialogCreateAlert"}

V/sl4a.JsonRpcServer:117(27913): Sent: {"error":null,"id":9,"result":null}

V/sl4a.JsonRpcServer:74(27913): Received: {"params": ["Ok"], "id": 10, "method": "dialogSetPositiveButtonText"}

V/sl4a.JsonRpcServer:117(27913): Sent: {"error":null,"id":10,"result":null}

V/sl4a.JsonRpcServer:74(27913): Received: {"params": [], "id": 11, "method": "dialogShow"}

I/ActivityManager( 1304): Starting: Intent { flg=0x18000000 cmp=com.googlecode.android_scripting/.activity.FutureActivity (has extras) } from pid 27913

D/sl4a.ConsoleActivity:746(27913): onPause called

编辑13/09/2012 09:55:我尝试了Bluetooth Chat App(BILL RAY)来自市场,它允许我的两部手机聊天,我可以从任何一方连接:问题可以解决至少Java。 bluetooth_chat.py示例仍无效。

编辑10:45:我仍然在SL4A中使用BeanShell尝试同样的问题,在我的S2上工作并且在我的Winmate上失败:

代码:

source("/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh");

droid = Android();

droid.call("makeToast", "Hello, Android!");

address = "00:12:F3:11:DC:E5";

uuid = "00001101-0000-1000-8000-00805F9B34FB";

droid.call("toggleBluetoothState","True");

droid.call("bluetoothConnect",uuid, address);

droid.call("makeToast", "Bye, Android!");

logcat类似:

I/ActivityManager( 1305): Starting: Intent { act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.android.settings/.bluetooth.RequestPermissionActivity } from pid 7364

D/dalvikvm( 7364): GC_CONCURRENT freed 1075K, 49% free 3716K/7239K, external 4198K/5242K, paused 2ms+14ms

V/sl4a.JsonRpcServer:117( 7364): Sent: {"error":null,"id":0,"result":true}

I/HK/LatinKeyboardBaseView( 1385): closing org.pocketworkstation.pckeyboard.LatinKeyboardView@4078a040

V/sl4a.JsonRpcServer:74( 7364): Received: {"id":0,"method":"bluetoothConnect","params":["00001101-0000-1000-8000-00805F9B34FB","00:12:F3:11:DC:E5"]}

E/BluetoothService.cpp( 1305): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)

I/ActivityManager( 1305): Displayed com.googlecode.android_scripting/.activity.FutureActivity: +223ms

I/HK/LatinKeyboardBaseView( 1385): closing org.pocketworkstation.pckeyboard.LatinKeyboardView@4078a040

D/sl4a.ConsoleActivity:761( 7364): onResume called

E/BluetoothEventLoop.cpp( 1305): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1804/hci0/dev_00_12_F3_11_DC_E5

I/ActivityManager( 1305): Start proc com.google.android.carhome for broadcast com.google.android.carhome/.receiver.BluetoothLaunchReceiver: pid=7876 uid=10020 gids={3002, 3001}

I/HK/LatinKeyboardBaseView( 1385): closing org.pocketworkstation.pckeyboard.LatinKeyboardView@4078a040

I/ActivityThread( 7876): Pub com.google.android.carhome.config: com.google.android.carhome.CarHomeProvider

D/BluetoothService( 1305): updateDeviceServiceChannelCache(00:12:F3:11:DC:E5)

D/BluetoothService( 1305): uuid(application): 00001101-0000-1000-8000-00805f9b34fb 1

D/BluetoothService( 1305): Making callback for 00001101-0000-1000-8000-00805f9b34fb with result 1

D/dalvikvm( 7364): GC_EXTERNAL_ALLOC freed 50K, 49% free 3698K/7239K, external 4198K/5242K, paused 131ms

V/BluetoothEventRedirector( 7681): Received android.bleutooth.device.action.UUID

I/BluetoothEventLoop.cpp( 1305): agent_event_filter: Received method org.bluez.Agent:OutOfBandAvailable

I/sl4a.TerminalBridge:540( 7364): parentChanged() now width=133, height=34

E/sl4a.JsonRpcServer:101( 7364): Invocation error.

E/sl4a.JsonRpcServer:101( 7364): java.io.IOException: Connection refused

E/sl4a.JsonRpcServer:101( 7364): at android.bluetooth.BluetoothSocket.connectNative(Native Method)

E/sl4a.JsonRpcServer:101( 7364): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:204)

E/sl4a.JsonRpcServer:101( 7364): at com.googlecode.android_scripting.facade.BluetoothFacade.bluetoothConnect(BluetoothFacade.java:158)

E/sl4a.JsonRpcServer:101( 7364): at java.lang.reflect.Method.invokeNative(Native Method)

E/sl4a.JsonRpcServer:101( 7364): at java.lang.reflect.Method.invoke(Method.java:507)

E/sl4a.JsonRpcServer:101( 7364): at com.googlecode.android_scripting.jsonrpc.RpcReceiverManager.invoke(RpcReceiverManager.java:87)

E/sl4a.JsonRpcServer:101( 7364): at com.googlecode.android_scripting.facade.FacadeManager.invoke(FacadeManager.java:58)

E/sl4a.JsonRpcServer:101( 7364): at com.googlecode.android_scripting.rpc.MethodDescriptor.invoke(MethodDescriptor.java:109)

E/sl4a.JsonRpcServer:101( 7364): at com.googlecode.android_scripting.jsonrpc.JsonRpcServer.handleConnection(JsonRpcServer.java:99)

E/sl4a.JsonRpcServer:101( 7364): at com.googlecode.android_scripting.SimpleServer$ConnectionThread.run(SimpleServer.java:91)

V/sl4a.JsonRpcServer:117( 7364): Sent: {"error":"java.io.IOException: Connection refused","id":0,"result":null}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
连接蓝牙设备,首先需要使用 BluetoothAdapter 的 startDiscovery() 方法扫描周围的蓝牙设备,然后通过 BluetoothDevice 类获取要连接蓝牙设备的实例,最后使用 BluetoothSocket 类进行连接。 以下是连接蓝牙设备的示例代码: ```java BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.startDiscovery(); // 开始扫描蓝牙设备 // 监听蓝牙设备的扫描结果 BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { // 获取扫描到的蓝牙设备 BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device.getName().equals("要连接蓝牙设备名称")) { // 停止扫描蓝牙设备 bluetoothAdapter.cancelDiscovery(); // 连接蓝牙设备 try { BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID.fromString("要连接蓝牙设备的UUID")); socket.connect(); // 连接蓝牙设备 } catch (IOException e) { e.printStackTrace(); } } } } }; IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); registerReceiver(receiver, filter); ``` 在上述代码中,我们首先获取了默认的 BluetoothAdapter 实例,然后调用 startDiscovery() 方法开始扫描蓝牙设备。通过注册一个 BroadcastReceiver 来监听蓝牙设备的扫描结果,当扫描到要连接蓝牙设备时,停止扫描蓝牙设备,使用 BluetoothDevice 类的 createRfcommSocketToServiceRecord() 方法获取 BluetoothSocket 对象,然后使用 connect() 方法连接蓝牙设备。 需要注意的是,连接蓝牙设备需要获得相应的权限。在 AndroidManifest.xml 文件中添加以下权限: ```xml <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值