Merge "AudioManager: update javadoc for setCommunicationDevice" into sc-dev

This commit is contained in:
Eric Laurent
2021-03-11 17:02:17 +00:00
committed by Android (Google) Code Review

View File

@@ -7084,26 +7084,22 @@ public class AudioManager {
* <pre class="prettyprint"> * <pre class="prettyprint">
* // Get an AudioManager instance * // Get an AudioManager instance
* AudioManager audioManager = Context.getSystemService(AudioManager.class); * AudioManager audioManager = Context.getSystemService(AudioManager.class);
* try { * AudioDeviceInfo speakerDevice = null;
* AudioDeviceInfo speakerDevice = null; * List<AudioDeviceInfo> devices = audioManager.getAvailableCommunicationDevices();
* List<AudioDeviceInfo> devices = audioManager.getAvailableCommunicationDevices(); * for (AudioDeviceInfo device : devices) {
* for (AudioDeviceInfo device : devices) { * if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
* if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) { * speakerDevice = device;
* speakerDevice = device; * break;
* break;
* }
* } * }
* if (speakerDevice != null) { * }
* // Turn speakerphone ON. * if (speakerDevice != null) {
* boolean result = audioManager.setCommunicationDevice(speakerDevice); * // Turn speakerphone ON.
* if (!result) { * boolean result = audioManager.setCommunicationDevice(speakerDevice);
* // Handle error. * if (!result) {
* } * // Handle error.
* // Turn speakerphone OFF.
* audioManager.clearCommunicationDevice();
* } * }
* } catch (IllegalArgumentException e) { * // Turn speakerphone OFF.
* // Handle exception. * audioManager.clearCommunicationDevice();
* } * }
* </pre> * </pre>
* @param device the requested audio device. * @param device the requested audio device.