Kotlin 通过反射实现清除蓝牙配对记录

    技术2022-07-10  150

    直接上代码

    /** * 监听事件 */ fun onClick(){ search_bt!!.setOnClickListener{ Toast.makeText(this,"正在查询中...",Toast.LENGTH_LONG).show() var bluetooth : Set<BluetoothDevice> = setOf() bluetooth = bluetoothAdapter!!.bondedDevices for (bluetoothDevice in bluetooth){ show_tv!!.setText(bluetoothDevice.name) cancelPair(bluetoothDevice) } } } /** * 取消蓝牙配对记录 */ fun cancelPair(device : BluetoothDevice){ try { var m : Method = device.javaClass.getMethod("removeBond") m.invoke(device) }catch (e : Exception){ e.printStackTrace() } }
    Processed: 0.011, SQL: 9