繁体   English   中英

如何使用 a2dp 和 avrcp 蓝牙配置文件连接两个 android 设备?

[英]How to connect two android devices using a2dp and avrcp bluetooth profiles?

我正在尝试在两个 android 设备之间实现 a2dp 和 avrcp,我找不到任何合适的参考。 我找到了一些,但没有太大帮助。

if (mBluetoothAdapter == null && !mBluetoothAdapter.isEnabled()) {
        Toast.makeText(this, "Bluetooth not enabled", Toast.LENGTH_SHORT).show();
        return;
    }


    mBluetoothAdapter.setName("MyGalaxy");
    mBluetoothAdapter.getProfileProxy(this, new BluetoothProfile.ServiceListener() {
        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            mA2DPSinkProxy = proxy;
            enableDiscoverable();
        }

        @Override
        public void onServiceDisconnected(int profile) {
        }
    }, A2DP_SINK_PROFILE);

BluetoothProfileManager profileManager = BluetoothProfileManager.getInstance();

    List<Integer> enabledProfiles = profileManager.getEnabledProfiles();
    String enabled = "";
    for (Integer profile : enabledProfiles) {
        enabled += ("" + profile + ", ");
    }
    Log.d(TAG, "Enabled Profiles - " + enabled);

    Log.d(TAG, "Enabling A2dp source mode.");
    List toEnable = Arrays.asList(BluetoothProfile.A2DP);
    List toDisable = Arrays.asList(A2DP_SINK_PROFILE, AVRCP_CONTROLLER_PROFILE);
    profileManager.enableAndDisableProfiles(toEnable, toDisable);

我收到此错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bluetootha2dpeg1, PID: 30451
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/bluetooth/BluetoothProfileManager;
    at com.example.bluetootha2dpeg1.MainActivity.setupBluetoothProfiles(MainActivity.java:157)
    at com.example.bluetootha2dpeg1.MainActivity.initA2DPSink(MainActivity.java:145)
    at com.example.bluetootha2dpeg1.MainActivity.initBluetooth(MainActivity.java:70)
    at com.example.bluetootha2dpeg1.MainActivity.onCreate(MainActivity.java:58)

BluetoothProfileManager仅适用于 Android Things 设备,不适用于手机或平板电脑。

另一个问题是 android 设备用作音乐源,而不是接收器,即它有一个 2dp 源配置文件,您不能在您的应用程序中更改它。 这只能通过修改android源代码来实现。

因此,如果您想将一台 android 设备用作蓝牙音乐接收器,您需要在 AOSP 中进行一些更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM