AudioManager.SetCommunicationDevice(AudioDeviceInfo) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Selects the audio device that should be used for communication use cases, for instance voice or video calls.
[Android.Runtime.Register("setCommunicationDevice", "(Landroid/media/AudioDeviceInfo;)Z", "GetSetCommunicationDevice_Landroid_media_AudioDeviceInfo_Handler", ApiSince=31)]
public virtual bool SetCommunicationDevice (Android.Media.AudioDeviceInfo device);
[<Android.Runtime.Register("setCommunicationDevice", "(Landroid/media/AudioDeviceInfo;)Z", "GetSetCommunicationDevice_Landroid_media_AudioDeviceInfo_Handler", ApiSince=31)>]
abstract member SetCommunicationDevice : Android.Media.AudioDeviceInfo -> bool
override this.SetCommunicationDevice : Android.Media.AudioDeviceInfo -> bool
Parameters
- device
- AudioDeviceInfo
the requested audio device.
Returns
true
if the request was accepted, false
otherwise.
- Attributes
Remarks
Selects the audio device that should be used for communication use cases, for instance voice or video calls. This method can be used by voice or video chat applications to select a different audio device than the one selected by default by the platform.
The device selection is expressed as an AudioDeviceInfo
among devices returned by #getAvailableCommunicationDevices()
. Note that only devices in a sink role (AKA output devices, see AudioDeviceInfo#isSink()
) can be specified. The matching source device is selected automatically by the platform.
The selection is active as long as the requesting application process lives, until #clearCommunicationDevice
is called or until the device is disconnected. It is therefore important for applications to clear the request when a call ends or the the requesting activity or service is stopped or destroyed.
In case of simultaneous requests by multiple applications the priority is given to the application currently controlling the audio mode (see #setMode(int)
). This is the latest application having selected mode #MODE_IN_COMMUNICATION
or mode #MODE_IN_CALL
. Note that MODE_IN_CALL
can only be selected by the main telephony application with permission Manifest.permission#MODIFY_PHONE_STATE
.
If the requested devices is not currently available, the request will be rejected and the method will return false.
This API replaces the following deprecated APIs: <ul> <li> #startBluetoothSco()
<li> #stopBluetoothSco()
<li> #setSpeakerphoneOn(boolean)
</ul> <h4>Example</h4>
The example below shows how to enable and disable speakerphone mode.
// Get an AudioManager instance
AudioManager audioManager = Context.getSystemService(AudioManager.class);
AudioDeviceInfo speakerDevice = null;
List<AudioDeviceInfo> devices = audioManager.getAvailableCommunicationDevices();
for (AudioDeviceInfo device : devices) {
if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
speakerDevice = device;
break;
}
}
if (speakerDevice != null) {
// Turn speakerphone ON.
boolean result = audioManager.setCommunicationDevice(speakerDevice);
if (!result) {
// Handle error.
}
// Turn speakerphone OFF.
audioManager.clearCommunicationDevice();
}
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.