android 蓝牙问题

想让自己的应用从蓝牙接收声音,想用蓝牙录音,哈哈哈哈。。。。。。。
困扰我两个星期的问题终于解决掉了,,,

1.修改menifest
加上这么一句话, <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
2.在自己的应用里播放声音的地方加上
AudioManager mAudioManager = (AudioManager) getContext()
.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, true);
mAudioManager.startBluetoothSco();
mAudioManager.setBluetoothScoOn(true);

就可以在蓝牙耳机里面听到动人的音乐了,吼吼 哈哈

英文好的同学请继续:o(∩∩)o...哈哈
readthefucksource!!!

 


/**
* Start bluetooth SCO audio connection.
* <p>Requires Permission:
* {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS}.
* <p>This method can be used by applications wanting to send and received audio
* to/from a bluetooth SCO headset while the phone is not in call.
* <p>As the SCO connection establishment can take several seconds,
* applications should not rely on the connection to be available when the method
* returns but instead register to receive the intent {@link #ACTION_SCO_AUDIO_STATE_CHANGED}
* and wait for the state to be {@link #SCO_AUDIO_STATE_CONNECTED}.
* <p>As the connection is not guaranteed to succeed, applications must wait for this intent with
* a timeout.
* <p>When finished with the SCO connection or if the establishment times out,
* the application must call {@link #stopBluetoothSco()} to clear the request and turn
* down the bluetooth connection.
* <p>Even if a SCO connection is established, the following restrictions apply on audio
* output streams so that they can be routed to SCO headset:
* - the stream type must be {@link #STREAM_VOICE_CALL}
* - the format must be mono
* - the sampling must be 16kHz or 8kHz
* <p>The following restrictions apply on input streams:
* - the format must be mono
* - the sampling must be 8kHz
*
* <p>Note that the phone application always has the priority on the usage of the SCO
* connection for telephony. If this method is called while the phone is in call
* it will be ignored. Similarly, if a call is received or sent while an application
* is using the SCO connection, the connection will be lost for the application and NOT
* returned automatically when the call ends.
* @see #stopBluetoothSco()
* @see #ACTION_SCO_AUDIO_STATE_CHANGED
*/
public void startBluetoothSco(){
IAudioService service = getService();
try {
service.startBluetoothSco(mICallBack);
} catch (RemoteException e) {
Log.e(TAG, "Dead object in startBluetoothSco", e);
}
}

posted @ 2012-08-03 20:37  beiju  阅读(1885)  评论(6编辑  收藏  举报