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

  • 相关阅读:
    android 保存图片,及将图片更新到图库
    android 点击数字跳转到电话界面
    使用Picasso将加载的图片变成圆形
    如何获取listview里面的edittext或者RadioGroup的值,涉及到引发的混乱现象
    返回页面,并将此页面数据刷新一遍
    DrawerLayout建立侧滑时,显示侧滑页面,底层页面仍可以有点击响应,解决办法。
    实现双击退出程序
    sql语句查找某一列的值得最大值。
    vue 实战笔记一项目准备
    node的基础知识
  • 原文地址:https://www.cnblogs.com/zhenbeiju/p/2622232.html
Copyright © 2011-2022 走看看