omn*_*iyo 7 sockets android bluetooth
我正在尝试将我的Nexus 4与Wii平衡板连接,但我收到此错误:
getBluetoothService() called with no BluetoothManagerCallback
connect(), SocketState: INIT, mPfd: null
Run Code Online (Sandbox Code Playgroud)
所以它没有完成连接.
我的插座:
public final class wSocket
{
public static BluetoothSocket create(BluetoothDevice dev, int port)
{
try {
/*
* BluetoothSocket(int type, int fd, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid)
*/
Constructor<BluetoothSocket> construct = BluetoothSocket.class.getDeclaredConstructor(int.class, int.class, boolean.class,
boolean.class, BluetoothDevice.class, int.class, ParcelUuid.class);
construct.setAccessible(true);
return construct.newInstance(3 /* TYPE_L2CAP */, -1, false, false, dev, port, null);
} catch (Exception ex) {
return null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它给我的错误:
private BluetoothSocket sk;
...
sk = wSocket.create(wm.dev, 0x11);
...
sk.connect();
Run Code Online (Sandbox Code Playgroud)
我检查此链接没有成功,因为我只打开1个套接字: getbluetoothservice()调用没有bluetoothmanagercallback
有什么帮助或想法去探索?
小智 1
getDefaultAdapter()尝试在创建套接字对象之前通过获取BluetoothAdapter 。当上述调用引用 BLuetoothAdater 时,似乎会创建回调服务。有关详细信息:
https: //android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothAdapter.java
当被调用时,哪里mService = managerService.registerAdapter(mManagerCallback);加载了值 getDefaultAdapter。
对于套接字 connect(),getBluetoothService() 参数始终为 null,请参见下面的代码:
ps 看来谷歌没有直接宣传BluetoothSocket构造函数的使用,并要求使用BluetoothDevice的方法来创建套接字。(来自谷歌网站上的参考)我不知道背后的原因。
| 归档时间: |
|
| 查看次数: |
23132 次 |
| 最近记录: |