2014-08-27 4 views
1

내 앱에서 재생하는 모든 오디오를 블루투스 스피커로 리디렉션하려고합니다. 처음에는 블루투스 장치를 페어링하고 난 재생 모든 오디오는 블루투스 speeker 전송되어야 함을의 audioManager에 '말'로 시도 :안드로이드 장치에서 블루투스 스피커로 오디오를 리디렉션하는 방법

private final BluetoothAdapter _bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 

public void pairBluetoothDevice(BluetoothDevice bluetoothDevice) 
{ 
    BluetoothSocket socket= bluetoothDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString("0000111E-0000-1000-8000-00805F9B34FB")); 
    socket.connect(); 

    _bluetoothAdapter.getProfileProxy(_appContext, _profileListener, BluetoothProfile.HEADSET); 
} 

private BluetoothProfile.ServiceListener _profileListener = new BluetoothProfile.ServiceListener() 
{ 
    public void onServiceConnected(int profile, BluetoothProfile proxy) 
    { 
    if (profile == BluetoothProfile.HEADSET) 
    { 
     _bluetoothHeadset = (BluetoothHeadset) proxy; 
     _bluetoothHeadset.startVoiceRecognition(_device); 

     AudioManager audioManager = (AudioManager) _appContext.getSystemService(Context.AUDIO_SERVICE); 
     audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); 
     audioManager.startBluetoothSco(); 
     audioManager.setBluetoothScoOn(true); 
     audioManager.setSpeakerphoneOn(false); 
    } 
    } 

    public void onServiceDisconnected(int profile) 
    { 
    if (profile == BluetoothProfile.HEADSET) 
    { 
     AudioManager audioManager= (AudioManager) _appContext.getSystemService(Context.AUDIO_SERVICE); 
     audioManager.setBluetoothScoOn(false); 
     audioManager.stopBluetoothSco(); 
     audioManager.setMode(AudioManager.MODE_NORMAL); 
     audioManager.setSpeakerphoneOn(true); 

     _bluetoothHeadset.stopVoiceRecognition(_device); 
     _bluetoothHeadset= null; 
    } 
    } 
}; 

나는 오디오 재생 ...

_soundPool.play(_soundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed); 

... 나는 아무 것도 듣지 못합니다. 나는 다음과 같은 해결 방법을 찾을

답변

1

:-) 어떤 힌트

감사 : 은 내가 블루투스 스피커를 페어링 오디오가 자동으로 스피커로 전송됩니다보다는 수있는 기본 블루투스 설정을 엽니 다.

startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS)); 
관련 문제