如何使用a2dp和avrcp蓝牙模式连接两台android设备?

如何使用a2dp和avrcp蓝牙模式连接两台android设备?,android,bluetooth,a2dp,avrcp,bluetoothadapter,Android,Bluetooth,A2dp,Avrcp,Bluetoothadapter,我试图在两台android设备之间实现a2dp和avrcp,我找不到任何合适的参考。我发现了一些,但没有太大帮助 if (mBluetoothAdapter == null && !mBluetoothAdapter.isEnabled()) { Toast.makeText(this, "Bluetooth not enabled", Toast.LENGTH_SHORT).show(); return; } mBluetoo

我试图在两台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=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);
BluetoothProfileManager仅适用于Android Things设备,不适用于手机或平板电脑

另一个问题是android设备作为音乐源工作,而不是接收器,也就是说,它有一个a2dp源配置文件,你不能在你的应用程序中更改它。这只有通过修改android源代码才能实现

因此,如果你想让一台android设备充当蓝牙音乐接收器,你需要在AOSP中做一些更改

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)