All Projects → jzconfidant → BluetoothOperator

jzconfidant / BluetoothOperator

Licence: other
实现Android手机蓝牙设备的扫描、过滤、连接,通过蓝牙串口功能向设备发送指定的信息。

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to BluetoothOperator

nxbt
Control your Nintendo Switch through a website, terminal, or macro.
Stars: ✭ 340 (+2328.57%)
Mutual labels:  bluetooth
gobot
Golang framework for robotics, drones, and the Internet of Things (IoT)
Stars: ✭ 7,869 (+56107.14%)
Mutual labels:  bluetooth
open-watch
An open-source handmade smartwatch. All of the codes, PCBs and schematics are available. ⌚
Stars: ✭ 35 (+150%)
Mutual labels:  bluetooth
rAudio-1
Raspberry Pi audio player: AirPlay, Audio CD, Bluetooth, DAB radio, DSP, Internet rafio, Multi-room, Spotify Connect, UPnP
Stars: ✭ 151 (+978.57%)
Mutual labels:  bluetooth
Apple-Signal
Connect Apple devices via bluetooth and wifi.
Stars: ✭ 27 (+92.86%)
Mutual labels:  bluetooth
H.E.L.P.
Home Environment Locating People 🍍
Stars: ✭ 19 (+35.71%)
Mutual labels:  bluetooth
Low power TTGO T-beam
Low power consumption for TTGO t-beam
Stars: ✭ 45 (+221.43%)
Mutual labels:  bluetooth
NeewerLite
NeewerLite is an un-official Neewer LED light control app for macOS.
Stars: ✭ 54 (+285.71%)
Mutual labels:  bluetooth
Bluetoothlib
This is a Bluetooth Library
Stars: ✭ 35 (+150%)
Mutual labels:  bluetooth
bluetooth-serial-port
multi-platform bluetooth serial port library for C++
Stars: ✭ 59 (+321.43%)
Mutual labels:  bluetooth
radonreader
Read current radon level from RadonEye RD200
Stars: ✭ 46 (+228.57%)
Mutual labels:  bluetooth
Echo
A simple iOS application redirects microphone input to the Bluetooth audio device
Stars: ✭ 33 (+135.71%)
Mutual labels:  bluetooth
arduino-ble-gadget
Create your own Do-It-Yourself BLE enabled sensor gadget on the ESP32 platform.
Stars: ✭ 31 (+121.43%)
Mutual labels:  bluetooth
gnome-keysign
An easier way to sign OpenPGP keys over the local network. A GTK/GNOME application to use GnuPG for signing other peoples' keys. Quickly, easily, and securely.
Stars: ✭ 42 (+200%)
Mutual labels:  bluetooth
pycalima
Python interface for Pax Calima Fan via Bluetooth LE
Stars: ✭ 34 (+142.86%)
Mutual labels:  bluetooth
ios
CoThings's iOS application. CoThings is a realtime counter for shared things.
Stars: ✭ 13 (-7.14%)
Mutual labels:  bluetooth
mikoto
Bluetooth LE nRF52840 microcontroller in a pro-micro footprint.
Stars: ✭ 139 (+892.86%)
Mutual labels:  bluetooth
nrf52832-pac
Peripheral Access Crate for the nRF52832 microcontroller
Stars: ✭ 21 (+50%)
Mutual labels:  bluetooth
hcitool
Bluetooth Host Controller Interface Command Line Tool for for sending HCI commands on macOS and Linux
Stars: ✭ 72 (+414.29%)
Mutual labels:  bluetooth
BluetoothChat
☉‿⊙ Simple bluetooth chat app.
Stars: ✭ 96 (+585.71%)
Mutual labels:  bluetooth

BluetoothLibrary

使用步骤

初始化

要使用BluetoothLibrary,首先要构造一个BluetoothOperator对象,用于操作蓝牙设备。建议的 做法是在Activity的onCreate()函数中完成初始化,如下:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBluetoothOp = new BluetoothOperator(this);
    mBluetoothOp.registerCallback(callback);
    if (mBluetoothOp.isEnabled())
        hasEnabled = true;
}

使能蓝牙功能

mBluetoothOp.enable();

protected void onResume() {
    super.onResume();

    mBluetoothOp.enable();
}

禁用蓝牙功能

mBluetoothOp.disable();

protected void onDestroy() {
    super.onDestroy();

    mBluetoothOp.unregisterCallback(callback);
    if (!hasEnabled)
        mBluetoothOp.disable();
    mBluetoothOp.destroy();
}

注册回调

BluetoothOperationCallback用于接收反馈信息,如连接成功、收到数据。

private BluetoothOperationCallback callback = new BluetoothOperationCallback() {

    @Override
    public void onConnect(int err, String desc) {
        if (err == 0) {
            Log.d(TAG, "Bluetooth connect success");
            mBluetoothOp.write("hello".getBytes());
        }
    }

    @Override
    public void onDataRecv(int err, String desc, byte[] data, int len) {
        if (err == 0) {
            Log.d(TAG, "Bluetooth receive data:" + new String(data, 0, len));
        }
    }
};

mBluetoothOp.registerCallback(callback);

取消注册

调用BluetoothOperator.unregisterCallback(callback)。

建立连接

调用mBluetoothOp.connect(),成功建立连接之后会通过onConnect()通知用户。

发送数据

调用mBluetoothOp.write();

接收数据

当接收到数据之后,会通过onDataRecv()通知用户(前提是用户注册过callback)。

释放资源

mBluetoothOp.destrory()

注意事项

在用于不在使用BluetoothOperator的时候,必须调用BluetoothOperator.destroy()来释放所有 的资源。

代码可参考BluetoothLibrary库里面的测试代码。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].