android - 牛轧糖套接字关闭时无法连接蓝牙

标签 android android-bluetooth

enter image description here我已成功导入谷歌示例蓝牙聊天项目并修复运行时权限但无法连接设备。套接字关闭我试了很多但不幸的是无法解决这个问题请帮助解决这个问题

最佳答案

我对这个“java.io.IOException: read failed, socket might closed or timeout, read ret: -1”的个人经验

以我为例。蓝牙设备已连接到另一台设备并测试了连接。后来,我断开了与另一台设备的连接并尝试连接到我的设备,但未建立连接。

多次打开和关闭设备后。我的设备已连接到蓝牙设备。

连设备都断开了。设备连接的地址未从设备中删除。我正在使用条形码扫描仪设备。

有这样的可能性。请通过关闭和打开蓝牙设备并重置蓝牙设备来检查一次。

这样试试

try {
mmSocket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"));
mmSocket.connect();
} catch (IOException e) {
Log.d(TAG, "Fail Attempt1 : " + e.toString());

    try{
         mmSocket =(BluetoothSocket) mmDevice.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class}).invoke(mmDevice,1);
         mmSocket.connect();
        } catch (Exception e1){
            try {
                    mmSocket.close();
                } catch (IOException e5) {
}

关于android - 牛轧糖套接字关闭时无法连接蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50875056/

相关文章:

安卓权限 : App crashes needing bluetooth permission

使用 scanfilter 的 Android 蓝牙低功耗扫描问题

iphone - iPhone/Android 专用 CSS

android - 使用 FirebaseMessagingService 类时出现错误 "return type int is not compatible with Intent"

android - 在 Android 应用程序中更改字体会使应用程序崩溃 - 无法制作 native 字体

Android:Flutter 中的 Handler.post() 等价物

android - 在不丢失与设备的连接的情况下将蓝牙连接实现到服务或应用程序类

javascript - 我如何在网站上使用 http url fallback 制作跨浏览器 native 应用程序 url?

android - 有没有人将 Android 作为 Central 连接到 iOS 作为 Peripheral?

bluetooth - createBond 并不总是显示引脚对话框