我正在尝试在两个 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)