BluetoothA2dpSnippet.java 文件源码

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

项目:mobly-bundled-snippets 作者:
@TargetApi(Build.VERSION_CODES.KITKAT)
@RpcMinSdk(Build.VERSION_CODES.KITKAT)
@Rpc(
    description =
            "Connects to a paired or discovered device with A2DP profile."
                    + "If a device has been discovered but not paired, this will pair it."
)
public void btA2dpConnect(String deviceAddress) throws Throwable {
    BluetoothDevice device = BluetoothAdapterSnippet.getKnownDeviceByAddress(deviceAddress);
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
    mContext.registerReceiver(new PairingBroadcastReceiver(mContext), filter);
    Utils.invokeByReflection(sA2dpProfile, "connect", device);
    if (!Utils.waitUntil(
            () -> sA2dpProfile.getConnectionState(device) == BluetoothA2dp.STATE_CONNECTED,
            120)) {
        throw new BluetoothA2dpSnippetException(
                "Failed to connect to device "
                        + device.getName()
                        + "|"
                        + device.getAddress()
                        + " with A2DP profile within 2min.");
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号