Java Code Examples for android.bluetooth.BluetoothProfile#A2DP

The following examples show how to use android.bluetooth.BluetoothProfile#A2DP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AssistantService.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onServiceDisconnected(int profile) {
    Log.e("blueHeadsetListener", "onServiceDisconnected:" + profile);
    if (profile == BluetoothProfile.A2DP) {
        voiceMediator.setBluetoothA2dp(null);
    } else if (profile == BluetoothProfile.HEADSET) {
        voiceMediator.setBluetoothHeadset(null);
    }
}
 
Example 2
Source File: AssistantService.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
    Log.e("blueHeadsetListener", "onServiceConnected:" + profile);
    if (profile == BluetoothProfile.A2DP) {
        voiceMediator.setBluetoothA2dp((BluetoothA2dp) proxy);
    } else if (profile == BluetoothProfile.HEADSET) {
        voiceMediator.setBluetoothHeadset((BluetoothHeadset) proxy);
    }
}
 
Example 3
Source File: MainActivity.java    From BlueToothEatPhone with Apache License 2.0 5 votes vote down vote up
@Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            try {
                if (profile == BluetoothProfile.HEADSET) {
//                    bh = (BluetoothHeadset) proxy;
//                    if (bh.getConnectionState(mTouchObject.bluetoothDevice) != BluetoothProfile.STATE_CONNECTED){
//                        bh.getClass()
//                                .getMethod("connect", BluetoothDevice.class)
//                                .invoke(bh, mTouchObject.bluetoothDevice);
//                    }

                } else if (profile == BluetoothProfile.A2DP) {
                    /**使用A2DP的协议连接蓝牙设备(使用了反射技术调用连接的方法)*/
                    a2dp = (BluetoothA2dp) proxy;
                    if (a2dp.getConnectionState(currentBluetoothDevice) != BluetoothProfile.STATE_CONNECTED) {
                        a2dp.getClass()
                                .getMethod("connect", BluetoothDevice.class)
                                .invoke(a2dp, currentBluetoothDevice);
                        Toast.makeText(MainActivity.this,"请播放音乐",Toast.LENGTH_SHORT).show();
                        getBondedDevices();
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }