PairingActivity.java 文件源码

java
阅读 33 收藏 0 点赞 0 评论 0

项目:microbit 作者:
/**
 * Finds all bonded devices and tries to unbond it.
 */
private void unPairDevice() {
    ConnectedDevice connectedDevice = BluetoothUtils.getPairedMicrobit(this);
    String addressToDelete = connectedDevice.mAddress;
    // Get the paired devices and put them in a Set
    BluetoothAdapter mBluetoothAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    for(BluetoothDevice bt : pairedDevices) {
        logi("Paired device " + bt.getName());
        if(bt.getAddress().equals(addressToDelete)) {
            try {
                Method m = bt.getClass().getMethod("removeBond", (Class[]) null);
                m.invoke(bt, (Object[]) null);
            } catch(NoSuchMethodException | IllegalAccessException
                    | InvocationTargetException e) {
                Log.e(TAG, e.toString());
            }
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号