Android BLE Connection time interval

后端 未结 5 919
孤街浪徒
孤街浪徒 2020-12-01 04:23

I am developing a BLE application on Nexus 4 using Android BLE API. I have a few questions/doubts:

1) Is there a way to set/override the connection or notification i

5条回答
  •  萌比男神i
    2020-12-01 05:13

    I met auto disconnection problem same as your second question. Two ways to solve it:

    1) Manually pair you Android device with the remote device through Bluetooth setting before running your application.

    2) Or you can programmatically pair them in your code. Here's the pairing code I found online, which works for me

    private void pairDevice(BluetoothDevice device) {
            try {
                Log.d("pairDevice()", "Start Pairing...");
                Method m = device.getClass()
                        .getMethod("createBond", (Class[]) null);
                m.invoke(device, (Object[]) null);
                Log.d("pairDevice()", "Pairing finished.");
            } catch (Exception e) {
                Log.e("pairDevice()", e.getMessage());
            }
        }
    

提交回复
热议问题