我试图通过SCO发送应用程序的所有音频.

我能够成功发送音频,

但是当有来电时,我需要断开SCO表格,以便应用音频不会干扰通话,

问题是,当我尝试在通话后将音频重新路由到SCO时,它不起作用.

这是我用来将音频发送到SCO的代码:

public class BluetoothManager {

// For Bluetooth connectvity

private static String TAG = "BluetoothManager";

private static BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

private static AudioManager aM;

/**

* Set the audio manager of the device.

* @param c: The context this method is called from

*/

public static void setAudioManager(Context c) {

aM = (android.media.AudioManager)c.getSystemService(Context.AUDIO_SERVICE);

}

/**

* Check if a Bluetooth headset is connected. If so, route audio to Bluetooth SCO.

*/

private static void initializeAudioMode(Context context) {

BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {

public void onServiceConnected(int profile, BluetoothProfile proxy) {

if (profile == BluetoothProfile.HEADSET) {

BluetoothHeadset bh = (BluetoothHeadset) proxy;

List devices = bh.getConnectedDevices();

if (devices.size() > 0) {

enableBluetoothSCO();

}

}

mBluetoothAdapter.closeProfileProxy(profile, proxy);

}

public void onServiceDisconnected(int profile) {}

};

mBluetoothAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.HEADSET);

}

/**

* Bluetooth Connectvity

* The following methods are associated with enabling/disabling Bluetooth.

* In the future we may want to disable other sources of audio.

*/

private static void enableBluetoothSCO() {

aM.setMode(AudioManager.MODE_IN_CALL);

aM.startBluetoothSco();

aM.setBluetoothScoOn(true);

}

/** Right now, this simply enables Bluetooth */

@SuppressLint("NewApi")

public static boolean enableBluetooth(Context c) {

// If there is an adapter, enable it if not already enabled

if (mBluetoothAdapter != null) {

if (!mBluetoothAdapter.isEnabled()) {

mBluetoothAdapter.enable();

}

setAudioManager(c);

initializeAudioMode(c);

Log.e(TAG, "SCO: " + aM.isBluetoothScoOn());

Log.e(TAG, "A2DP: " + aM.isSpeakerphoneOn());

return true;

} else {

Log.v(TAG, "There is no bluetooth adapter");

return false;

}

}

/** Right now, this simply disables Bluetooth */

public static void disableBluetooth() {

// If there is an adapter, disabled it if not already disabled

if (mBluetoothAdapter != null) {

if (mBluetoothAdapter.isEnabled()) {

mBluetoothAdapter.disable();

}

} else {

Log.v(TAG, "There is no bluetooth adapter");

}

}

public static void restartBluetooth(){

aM.setMode(AudioManager.MODE_IN_CALL);

}

public static void stopBluetooth(){

aM.setMode(AudioManager.MODE_NORMAL);

}

}

当我正确调用stopBluetooth()时,应用程序的音频不再发送到耳机,

但是,当我调用restartBluetooth()时,音频不是按预期播放耳机,而是来自手机扬声器.

android 三星 蓝牙sco,android – 来电后蓝牙SCO失败相关推荐

  1. android 三星调用拍照,Android拍照与相机适配问题汇总

    问题一:onActivityResult方法中的data返回为空. 问题原因:使用Intent调用手机内相机程序时,如果我们设置了照片的存储路径时,有数据表明,93%的机型的data将会是Null,所 ...

  2. 三星手机如何刷原生Android,必赢贵宾会「永久地址0365.tv」三星s8刷原生android三星i8320刷android大法。。。...

    2 接着是安装ylmfos系统 1) 首先,我们从下载到的 ISO 文件中解压出安装工具. 大家下载的 ISO 文件在 Windows 中多显示为压缩包格式,不管什么格式,只要能打开,找到其中的安装程 ...

  3. android 获取蓝牙信号强度,连接后获取蓝牙RSSI信号强度

    android 获取蓝牙信号强度,连接后获取蓝牙RSSI信号强度 基于蓝牙的RSSI可以有很多应用,要获得蓝牙的RSSI无外乎两种方法. 第一种:基于扫瞄的方法 优点是Android本身支持,缺点是s ...

  4. android spp传输速度,Android蓝牙SPP连接似乎在几秒后就已经死了

    我有一个相当简单的程序,主要基于这里发布的简单蓝牙测试客户端应用程序: 我的应用程序有4个按钮,每个按钮通过蓝牙连接发送不同的数据字节. 似乎工作得很好几秒钟.建立连接,RFCOMM插座连接,并在最初 ...

  5. Android BLE低功耗蓝牙重启手机后自动连接失败问题

    最近在做安卓开发,用到蓝牙模块相关功能.主要功能是使用手机连上低功耗蓝牙设备,比如蓝牙手环.关于如何蓝牙连接在这里就不讲述了,网上搜索一大堆相关教程.想要来这里看蓝牙连接方式的朋友可能要大失所望了. ...

  6. Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支持蓝牙4.0版本_BLE开发

    一.Android Bluetooth现状 在android官网可以了解到android4.2新增了部分新功能,但是对于BT熟悉的人或许开始头疼了,那就是Android4.2引入了一个新的蓝牙协议栈针 ...

  7. esp32与android蓝牙,ESP32蓝牙架构(官方)_esp32蓝牙,esp32如何连接手机蓝牙

    ESP32 蓝牙开发资料,用于了解ESP32内部的蓝牙实现. 本⼿册为 ESP32 的蓝⽛架构简介,主要分三个章节介绍了蓝⽛.经典蓝⽛和蓝⽛低功耗 ⽅⾯的整体架构.注意,本⼿册仅针对 ESP-IDF ...

  8. Android 蓝牙启动流程(以及设置蓝牙为作为sink模式 接收端模式)

    本文以Android 7.1为基础 最近在做蓝牙开发,研究了一下蓝牙的启动流程,总结一下 Google在Android源码中推出了它和博通公司一起开发的BlueDroid以替代BlueZ.BlueZ的 ...

  9. 【Android应用开发】Android 蓝牙低功耗 (BLE) ( 第一篇 . 概述 . 蓝牙低功耗文档 翻译)

    转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50515359 参考 :  -- 官方文档 : https://develope ...

最新文章

  1. Python-列表和元组
  2. mysql os.pid_离线安装Mysql
  3. java吵醒线程_一文搞懂 Java 线程中断
  4. poj2516 最小费用最大流
  5. 超图js版本添加矢量图层并在图层上绘一个面要素
  6. TensorFlow中RNN实现的正确打开方式
  7. 笔记本输入法, u、i 等字母变成了数字
  8. 微软发布架构师期刊阅读器
  9. 使用Keras进行深度学习:(三)使用text-CNN处理自然语言(上)
  10. 这样的促销海报,还怕卖不出去?
  11. ajax引入html_Vue中发送ajax请求的库有哪些?
  12. android 设置超时时间,为android requestSingleUpdate设置超时
  13. jerasure 2.0译文
  14. Redis 未授权访问 CNNVD-201511-230 漏洞复现
  15. 动手学深度学习 环境安装
  16. 电气防火限流式保护器及其过电流故障检测方法
  17. 关于vs2013弹出“正在初始化模板“的问题
  18. 字符编码那些事--彻底理解掌握编码知识
  19. html风琴图片展示,基于jquery的手风琴图片展示效果实现方法
  20. 新的一年,红包走起!

热门文章

  1. C语言反序输出英文句子,iOS开发-英文句子倒序输出
  2. 用python解矩阵方程_用Python的Numpy求解线性方程组
  3. 贝叶斯公式的对数似然函数_最大似然法与似然函数
  4. 一只喵的西行记-9 喵林英雄虹猫梦
  5. grub.cfg使用说明
  6. Spring Boot【定制化】~ AOP统一结果处理以及异常拦截
  7. 正益移动王国春:布局在是与不是之间
  8. C语言程序设计教程蒋清明,C语言程序设计教程(第2版)
  9. mysql数据库状态如何监控数据库_MySQL数据库之zabbix3.2监控MYSQL状态
  10. Riverbed SteelConnect荣获2017 Interop东京展“最佳展示奖”