功能简介
实现切换音频通道 蓝牙,外放,耳机
实现步骤
1.通过
mAudioManager
获取管理音频设备的实例
2.如何切换至耳机mAudioManager.setSpeakerphoneOn(false)
外放话筒关闭。mAudioManager.setBluetoothScoOn(false)
蓝牙关闭。
3.如何切换至蓝牙mAudioManager.setSpeakerphoneOn(false)
外放话筒关闭。>mAudioManager.startBluetoothSco()
启动蓝牙ScomAudioManager.setBluetoothScoOn(true);
设置socOn开启
4.如何切换至外放耳机,蓝牙,全都关闭
mAudioManager.setSpeakerphoneOn(true)
外放话筒打开
java代码
* Android技术生活-QQ交流群:723592501
public class DeviceSpeakerChangeUtil {
/**
* 简介:设备语音切换-蓝牙-外放-听筒
* 作者:YFZ
* 主要功能: 设备语音切换-蓝牙-外放-听筒
*/
private static AudioManager mAudioManager;
/**
* 切换到外放
*/
public static void changeToSpeaker(Context context){
deviceChangeToHeadPhone(context);
mAudioManager.setSpeakerphoneOn(true); //打开外放
}
/**
* 切换到蓝牙耳机
*/
public static void changeToBlueTooth(Context context){
deviceChangeToHeadPhone(context);
mAudioManager.startBluetoothSco(); //启动蓝牙耳机
mAudioManager.setBluetoothScoOn(true); //设置socOn开启,蓝牙耳机开启
}
/**
* 切换到耳机模式
*/
public static void deviceChangeToHeadPhone(Context context){
if(mAudioManager==null) {
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.stopBluetoothSco(); //停止蓝牙耳机
mAudioManager.setBluetoothScoOn(false); //设蓝牙ScoOn关闭,蓝牙耳机则会停止
mAudioManager.setSpeakerphoneOn(false); //设置外放话筒关闭
}
}
Android技术生活交流
----- qq群
![]()
---------------------
作者:我是giggleman
来源:CSDN
原文:https://blog.csdn.net/ruiruiddd/article/details/116064606
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件