将手机麦克风路由到Android中的Sco蓝牙耳机

将手机麦克风路由到Android中的Sco蓝牙耳机,android,bluetooth,audio-streaming,headset,Android,Bluetooth,Audio Streaming,Headset,去年我的帖子上的这些机会让我看到了我在这个应用程序上的挣扎。 现在我已经到了最后阶段,我真的无法理解为什么代码不能工作。我想做的是将音频流从手机麦克风传送到sco蓝牙耳机。 手机为三星Galaxy s2,耳机为Esco Plastronics。 我遵循安卓网站上的文档,这是我迄今为止所做的: tools.Log("&&&&&&&& debug &&&&&&&&&

去年我的帖子上的这些机会让我看到了我在这个应用程序上的挣扎。 现在我已经到了最后阶段,我真的无法理解为什么代码不能工作。我想做的是将音频流从手机麦克风传送到sco蓝牙耳机。 手机为三星Galaxy s2,耳机为Esco Plastronics。 我遵循安卓网站上的文档,这是我迄今为止所做的:

tools.Log("&&&&&&&& debug &&&&&&&&&","");
tools.Log("&&&&&&&& debug &&&&&&&&&","");
tools.Log("&&&&&&&& debug &&&&&&&&&","");
tools.Log("FBR.SetUpAudioRecoder", "In");
public static final int SAMPPERSER =  8000;
public int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
public int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
public AudioManager AM = (AudioManager) mcontext.getSystemService(Context.AUDIO_SERVICE);

buffersizebytes = AudioRecord.getMinBufferSize(SAMPPERSEC,channelConfiguration, audioEncoding);     buffersizebytes = (short) (buffersizebytes * 20);
audioRecord = new AudioRecord(
      android.media.MediaRecorder.AudioSource.MIC,SAMPPERSEC,channelConfiguration,audioEncoding,buffersizeb   ytes); // constructor
//Debug
boolean tmp = AM.isBluetoothScoAvailableOffCall();//Returns true
tools.Log("AM.isBluetoothScoAvailableOffCall() is -",tools.BoolToString(tmp));
try {
    audioRecord.startRecording();
} catch (IllegalStateException e) {
    tools.Log("FBR.GetAudioFromMic:startRecording:Error ",
                e.getMessage());
    return "Get Audio From Mic Error";
}
AM.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
AM.setBluetoothScoOn(true);
AM.startBluetoothSco();// HERE I GET A BEEP ON THE HEADSET
tmp = AM.isBluetoothScoOn();// Returns true
tools.Log("AM.isBluetoothScoOn() is - ",    tools.BoolToString(tmp));
tools.Log("&&&&&&&& end debug &&&&&&&&&","");
tools.Log("&&&&&&&& end debug &&&&&&&&&","");
tools.Log("&&&&&&&& end debug &&&&&&&&&","");
清单文件上的权限为:

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>

非常感谢您在AM.setBluetoothScoOn(正确)前后提供的帮助,您可能需要调用AM.setMode(MODE_IN_COMMUNICATION)

@cv,你解决问题了吗?我也面临着同样的问题,录制的文件只包含静默,它似乎试图抓住蓝牙麦克风,但无法触及。我很惊讶它没有连接到手机麦克风,以防它没有连接到蓝牙麦克风。通过使用am.setBluetoothSco(true),设备将音频发送到蓝牙耳机和从蓝牙耳机发送出去。@Harish从未在android 4.0以上版本(Ice-ream sandwich)上实现过这一点,但这在android棒棒糖中不起作用。有解决方法吗?
20 08:56:02.090:D/SpySitter(9659): &&&&&&&&& debug &&&&&&&&&&-
01-20 08:56:02.090: D/SpySitter(9659): FBR.SetUpAudioRecoder-In

01-20 08:56:02.100: I/AudioHardwareYamaha(1833): getInputBufferSize() rate 8000, size 512 

01-20 08:56:02.110: I/AudioPolicyManager(1833): getDeviceForInputSource()input source 1, device 00100000

01-20 08:56:02.110: I/AudioHardwareYamaha(1833): AudioStreamIn::set(1, 16, 8000)

01-20 08:56:02.110: I/AudioHardwareYamaha(1833): bufferSize() channels 2, bufferRatio 4, size 1024

01-20 08:56:02.115: I/AudioHardwareYamaha(1833): AudioStreamIn::standby()

01-20 08:56:02.120: D/SpySitter(9659): AM.isBluetoothScoAvailableOffCall() is - -true

01-20 08:56:02.125: I/AudioService(1989): isMediaSilentMode false

20 08:56:02.140: I/AudioPolicyManager(1833): getDeviceForStrategy() strategy 4, device 2

01-20 08:56:02.145: I/AudioPolicyManager(1833): setForceUse() usage 2, config 3, mPhoneState 0

01-20 08:56:03.475: E/DataRouter(1828): usb connection is true 

01-20 08:56:03.475: E/DataRouter(1828): DSR is ON. Don't send DTR ON

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): initiateScoUsingVirtualVoiceCall: Received

01-20 08:56:05.010: V/Bluetooth AT sent(2240): +CIEV: 3,2

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): initiateScoUsingVirtualVoiceCall: Sent Call-setup 
procedure

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): audioOn()

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): setAudioState(11)

01-20 08:56:05.015: D/Bluetooth HSHFP(2240): AudioStateIntent:  State: 11 PrevState: 10

01-20 08:56:05.015: V/BluetoothSocket.cpp(2240): initSocketNative

01-20 08:56:05.015: V/BluetoothSocket.cpp(2240): ...fd 99 created (SCO, lm = 0)

01-20 08:56:05.015: V/BluetoothSocket.cpp(2240): initSocketFromFdNative

01-20 08:56:05.040: D/Bluetooth HS/HF(2240): initiateScoUsingVirtualVoiceCall: Done

01-20 08:56:05.045: I/BluetoothPolicyService(1989): isPairingEnabled 

01-20 08:56:05.055: D/BluetoothUtils(2240): isSocketAllowedBySecurityPolicy start : device null

01-20 08:56:05.055: V/BluetoothSocket.cpp(2240): connectNative

01-20 08:56:05.065: V/Bluetooth AT recv(2240): AT+CLCC

01-20 08:56:05.070: V/Bluetooth AT sent(2240): +CLCC: 1,0

01-20 08:56:05.080: V/BluetoothSocket.cpp(2240): ...connect(99, SCO) = 0 (errno 115)

01-20 08:56:05.080: D/Bluetooth HS/HF(2240): Routing audio for outgoing SCO conection

01-20 08:56:16.455: D/SpySitter(9659): &&&&&&&&&&&& end debug&&&&&&&&