Я хочу подождать, пока мое устройство не будет полностью сопряжено (BLE) - PullRequest
0 голосов
/ 19 июня 2019

Я работаю над BLE , но для соединения я хочу подождать в той же деятельности

Ответы [ 2 ]

0 голосов
/ 19 июня 2019

Спасибо тебе.Я сделал это, используя это

if(action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)){
            BluetoothDevice mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            //3 cases:
            //case1: bonded already
            if (mDevice.getBondState() == BluetoothDevice.BOND_BONDED){
                Log.d(TAG, "BroadcastReceiver: BOND_BONDED.");
                startActivity(intentNewActivity);
            }
            //case2: creating a bone
            if (mDevice.getBondState() == BluetoothDevice.BOND_BONDING) {
                Log.d(TAG, "BroadcastReceiver: BOND_BONDING.");
            }
            //case3: breaking a bond
            if (mDevice.getBondState() == BluetoothDevice.BOND_NONE) {
                Log.d(TAG, "BroadcastReceiver: BOND_NONE.");
            }
        }
0 голосов
/ 19 июня 2019

В вашем приложении. Регистрация приемника вещания для подключения Bluetooth

        val filter = IntentFilter()
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED)
        filter.addAction(BluetoothDevice.ACTION_FOUND)
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED)
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)
        filter.priority = IntentFilter.SYSTEM_HIGH_PRIORITY
        registerReceiver(mReceiver, filter)

внутри вашего приемника сделайте свое дело

 mReceiver = object : BroadcastReceiver() {
            override fun onReceive(context: Context, intent: Intent) {
   //Do your Stuff
  }
}
...