2017-08-10 20 views
2

VOIPアプリケーションでは、サイレントモードでアラートトーンまたは着信音がBluetoothヘッドセットでのみ再生されます。ヘッドフォンが接続されていればヘッドフォンで演奏することができますが、ヘッドセットが接続されていないと、モバイルはサイレントモードですが、トーンがスピーカーで再生されます。Bluetoothヘッドセットが接続されているかどうかを検出

誰かが、Bluetoothヘッドセットが接続されていることを検出する方法があるかどうかを説明してください。 Bluetoothヘッドセットの場合

答えて

0

感謝。 Detect programatically if headphone or bluetooth headset attached with android phone

Vipulは、ヘッドセットプロファイルを取得扱うBluetoothHeadsetManagerクラスを作成していたブロガーから呼ば

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

    @Override 
    public void onServiceConnected(int profile, BluetoothProfile proxy) 
    { 
     if (profile == BluetoothProfile.HEADSET) 
     { 
      mBluetoothHeadset = (BluetoothHeadset) proxy; 
      if(mBluetoothHeadset.getConnectedDevices().size()>0) { 
       IS_BLUETOOTH_CONNECTED = true; 
       Logs.d(TAG,"Bluetooth device is connected"); 
      } 

     } 
    } 

    @Override 
    public void onServiceDisconnected(int profile) 
    { 
     if (profile == BluetoothProfile.HEADSET) 
     { 
      mBluetoothHeadset = null; 
      IS_BLUETOOTH_CONNECTED = false; 
      Logs.d(TAG,"Bluetooth device is disconnected"); 
     } 
    } 
}; 

リスナーを作成したプロキシ

bluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET); 

Connectには、 、聞くことを扱うブルートゥースが有効かどうかをチェックします。ブロードキャストレシーバを利用していません。

switch (audioMgr.getRingerMode()) { 
     case AudioManager.RINGER_MODE_SILENT: 
      if(BluetoothHeadsetManager.IS_BLUETOOTH_CONNECTED) { 
       //play notification 
      } 
      break; 
     case AudioManager.RINGER_MODE_VIBRATE: 
      if(BluetoothHeadsetManager.IS_BLUETOOTH_CONNECTED) { 
       //play notification 
      } 
      break; 
     case AudioManager.RINGER_MODE_NORMAL: 
      //play ringtone 
      break; 
     default: 
      break; 
     }} 
関連する問題