Java Code Examples for android.media.AudioManager#SCO_AUDIO_STATE_DISCONNECTED
The following examples show how to use
android.media.AudioManager#SCO_AUDIO_STATE_DISCONNECTED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallActivity.java From sealrtc-android with MIT License | 6 votes |
@Override public void onNotifySCOAudioStateChange(int scoAudioState) { switch (scoAudioState) { case AudioManager.SCO_AUDIO_STATE_CONNECTED: AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am != null) { am.setBluetoothScoOn(true); } break; case AudioManager.SCO_AUDIO_STATE_DISCONNECTED: Log.d("onNotifyHeadsetState", "onNotifySCOAudioStateChange: " + headsetPlugReceiver.isBluetoothConnected()); if (headsetPlugReceiver.isBluetoothConnected()) { startBluetoothSco(); } break; } }
Example 2
Source File: BluetoothUtils8.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.d(THIS_FILE, ">>> BT SCO state changed !!! "); if(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED.equals(action)) { int status = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_ERROR ); Log.d(THIS_FILE, "BT SCO state changed : " + status + " target is " + targetBt); audioManager.setBluetoothScoOn(targetBt); if(status == AudioManager.SCO_AUDIO_STATE_CONNECTED) { isBluetoothConnected = true; }else if(status == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) { isBluetoothConnected = false; } if(btChangesListener != null) { btChangesListener.onBluetoothStateChanged(status); } } }
Example 3
Source File: BluetoothScoReceiver.java From Jumble with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int audioState = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_ERROR); switch (audioState) { case AudioManager.SCO_AUDIO_STATE_CONNECTED: mBluetoothScoOn = true; mListener.onBluetoothScoConnected(); break; case AudioManager.SCO_AUDIO_STATE_DISCONNECTED: case AudioManager.SCO_AUDIO_STATE_ERROR: am.stopBluetoothSco(); mBluetoothScoOn = false; mListener.onBluetoothScoDisconnected(); break; } }
Example 4
Source File: AudioManagerAndroid.java From 365browser with Apache License 2.0 | 4 votes |
/** * Registers receiver for the broadcasted intent related the existence * of a BT SCO channel. Indicates if BT SCO streaming is on or off. */ private void registerForBluetoothScoIntentBroadcast() { IntentFilter filter = new IntentFilter( AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED); /** BroadcastReceiver implementation which handles changes in BT SCO. */ mBluetoothScoReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra( AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_DISCONNECTED); if (DEBUG) { logd("BroadcastReceiver.onReceive: a=" + intent.getAction() + ", s=" + state + ", sb=" + isInitialStickyBroadcast()); } switch (state) { case AudioManager.SCO_AUDIO_STATE_CONNECTED: mBluetoothScoState = STATE_BLUETOOTH_SCO_ON; break; case AudioManager.SCO_AUDIO_STATE_DISCONNECTED: if (mBluetoothScoState != STATE_BLUETOOTH_SCO_TURNING_OFF) { // Bluetooth is probably powered off during the call. // Update the existing device selection, but only if a specific // device has already been selected explicitly. if (deviceHasBeenRequested()) { updateDeviceActivation(); } } mBluetoothScoState = STATE_BLUETOOTH_SCO_OFF; break; case AudioManager.SCO_AUDIO_STATE_CONNECTING: // do nothing break; default: loge("Invalid state"); } if (DEBUG) { reportUpdate(); } } }; ContextUtils.getApplicationContext().registerReceiver(mBluetoothScoReceiver, filter); }
Example 5
Source File: BluetoothController.java From dialogflow-android-client with Apache License 2.0 | 4 votes |
@SuppressWarnings({"deprecation", "synthetic-access"}) @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) { BluetoothDevice mConnectedHeadset = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothClass bluetoothClass = mConnectedHeadset.getBluetoothClass(); if (bluetoothClass != null) { // Check if device is a headset. Besides the 2 below, are there other // device classes also qualified as headset? int deviceClass = bluetoothClass.getDeviceClass(); if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) { // start bluetooth Sco audio connection. // Calling startBluetoothSco() always returns faIL here, // that why a count down timer is implemented to call // startBluetoothSco() in the onTick. mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mIsCountDownOn = true; mCountDown.start(); // override this if you want to do other thing when the device is connected. onHeadsetConnected(); } } Log.d(TAG, mConnectedHeadset.getName() + " connected"); } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { Log.d(TAG, "Headset disconnected"); if (mIsCountDownOn) { mIsCountDownOn = false; mCountDown.cancel(); } mAudioManager.setMode(AudioManager.MODE_NORMAL); // override this if you want to do other thing when the device is disconnected. onHeadsetDisconnected(); } else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED)) { int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_ERROR); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { mIsOnHeadsetSco = true; if (mIsStarting) { // When the device is connected before the application starts, // ACTION_ACL_CONNECTED will not be received, so call onHeadsetConnected here mIsStarting = false; onHeadsetConnected(); } if (mIsCountDownOn) { mIsCountDownOn = false; mCountDown.cancel(); } // override this if you want to do other thing when Sco audio is connected. onScoAudioConnected(); Log.d(TAG, "Sco connected"); } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) { Log.d(TAG, "Sco disconnected"); // Always receive SCO_AUDIO_STATE_DISCONNECTED on call to startBluetooth() // which at that stage we do not want to do anything. Thus the if condition. if (!mIsStarting) { mIsOnHeadsetSco = false; // Need to call stopBluetoothSco(), otherwise startBluetoothSco() // will not be successful. mAudioManager.stopBluetoothSco(); // override this if you want to do other thing when Sco audio is disconnected. onScoAudioDisconnected(); } } } }