0
回答
Android 蓝牙连接问题
华为云4核8G,高性能云服务器,免费试用   

项目需要做一个蓝牙设置,

在设置中去连接蓝牙鼠标,在scket.connect();中报如下错误:

部分源码:

public static void connect(final BluetoothDevice device) throws IOException {
		new Thread() {
			@Override
			public void run() {
				ParcelUuid[] uuids = device.getUuids();
				if (uuids == null) {
					return;
				}
				UUID uuid = uuids[0].getUuid();
				try {
					if (!connectting) {
						cancelDiscovery();
						Log.w(TAG, "终止搜索设备");
						socket = device.createRfcommSocketToServiceRecord(uuid);
						Log.w(TAG, "socket套接字创建完成");
						connectting = true;
						if (!socket.isConnected()) {
							socket.connect();
							Log.w(TAG, "connect成功!");
						}
					}
				} catch (IOException e) {
					e.printStackTrace();
					Log.w(TAG, "连接失败!");
					connectting = false;
				}
			}
		}.start();
	}



举报
Kerwin
发帖于2年前 0回/91阅
顶部