zoukankan      html  css  js  c++  java
  • 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);
    }
    }

  • 相关阅读:
    我要好offer之 二叉树大总结
    我要好offer之 字符串相关大总结
    楼层扔鸡蛋问题[转]
    Linux System Programming 学习笔记(十一) 时间
    Linux System Programming 学习笔记(十) 信号
    Linux System Programming 学习笔记(九) 内存管理
    Linux System Programming 学习笔记(八) 文件和目录管理
    Linux System Programming 学习笔记(七) 线程
    Linux System Programming 学习笔记(六) 进程调度
    APUE 学习笔记(十一) 网络IPC:套接字
  • 原文地址:https://www.cnblogs.com/zhenbeiju/p/2622232.html
Copyright © 2011-2022 走看看