本文共 3722 字,大约阅读时间需要 12 分钟。
转载请说明出处!
作者: 出处: |To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects { repositories { ... maven { url 'https://jitpack.io' } }}
Step 2. Add the dependency
dependencies { compile 'com.github.kongqw:AndroidBluetoothManager:1.0.0'}
mBluetoothManager = new BluetoothManager();
mBluetoothManager.openBluetooth();
mBluetoothManager.closeBluetooth();
mBluetoothManager.setOnBluetoothStateListener(this);
/** * 正在关闭蓝牙的回调 */@Overridepublic void onBluetoothStateTurningOff() { // TODO}/** * 蓝牙关闭的回调 */@Overridepublic void onBluetoothStateOff() { // TODO}/** * 正在打开蓝牙的回调 */@Overridepublic void onBluetoothStateTurningOn() { // TODO}/** * 蓝牙打开的回调 */@Overridepublic void onBluetoothStateOn() { // TODO}
mBluetoothManager.removeOnBluetoothStateListener();
startActivity(mBluetoothManager.getDurationIntent(0));
mBluetoothManager.getName()
mBluetoothManager.setName(newName);
mBluetoothManager.discovery();
mBluetoothManager.setOnDiscoveryDeviceListener(this);
/** * 开始扫描附近蓝牙设备的回调 */@Overridepublic void onDiscoveryDeviceStarted() { // TODO}/** * 扫描到附近蓝牙设备的回调 * * @param device 蓝牙设备 */@Overridepublic void onDiscoveryDeviceFound(BluetoothDevice device) { // TODO}/** * 扫描附近蓝牙设备完成的回调 */@Overridepublic void onDiscoveryDeviceFinished() { // TODO}
mBluetoothManager.removeOnDiscoveryDeviceListener();
mBluetoothService = new BluetoothService() { @Override protected UUID onSecureUuid() { // TODO 设置自己的UUID return UUID_SECURE; } @Override protected UUID onInsecureUuid() { // TODO 设置自己的UUID return UUID_INSECURE; }};
mBluetoothService.start();
mBluetoothService.stop();
mBluetoothService.setOnServiceConnectListener(new OnServiceConnectListener() { @Override public void onConnectListening() { // TODO } @Override public void onConnectSuccess(BluetoothDevice device) { // TODO } @Override public void onConnectFail(Exception e) { // TODO } @Override public void onConnectLost(Exception e) { // TODO }});
mBluetoothService.send(chatText);
mBluetoothClient.setOnMessageListener(this);
/** * 蓝牙发送了消息 * * @param message 发送的消息 */@Overridepublic void onSend(String message) { // TODO}/** * 蓝牙接收到消息 * * @param message 接收的消息 */@Overridepublic void onRead(String message) { // TODO}
mBluetoothClient = new BluetoothClient() { @Override protected UUID onSecureUuid() { // TODO 设置自己的UUID return UUID_SECURE; } @Override protected UUID onInsecureUuid() { // TODO 设置自己的UUID return UUID_INSECURE; }};
mBluetoothClient.connect(mBluetoothDevice, true);
mBluetoothClient.connect(mBluetoothDevice, false);
mBluetoothClient.stop();
mBluetoothClient.setOnClientConnectListener(new OnClientConnectListener() { @Override public void onConnecting() { // TODO } @Override public void onConnectSuccess(BluetoothDevice device) { // TODO } @Override public void onConnectFail(Exception e) { // TODO } @Override public void onConnectLost(Exception e) { // TODO }});
mBluetoothClient.send(chatText);
mBluetoothClient.setOnMessageListener(this);
/** * 蓝牙发送了消息 * * @param message 发送的消息 */@Overridepublic void onSend(String message) { // TODO}/** * 蓝牙接收到消息 * * @param message 接收的消息 */@Overridepublic void onRead(String message) { // TODO}