• 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);
    }
    }

  • 相关阅读:
    全链路压测(4):全链路压测的价值是什么?
    基于SVN的版本范围汇总
    一篇值得思考的职业教育之路!
    分享35个讨人喜欢的漂亮进度条UI设计
    转一篇难得的好文章CPU流水线的探秘之旅
    超棒的获奖动物摄影作品集
    解决web.py在SAE云中的Session使用问题
    2012年度最新免费web开发设计资源荟萃
    Endless icon: 每天都更新的图标集
    不容错过的超棒Javascript日期处理类库Moment.js
  • 原文地址:https://www.cnblogs.com/zhenbeiju/p/2622232.html
Copyright © 2020-2023  润新知