Example usage for android.media AudioManager getDevices

List of usage examples for android.media AudioManager getDevices

Introduction

In this page you can find the example usage for android.media AudioManager getDevices.

Prototype

public AudioDeviceInfo[] getDevices(int flags) 

Source Link

Document

Returns an array of AudioDeviceInfo objects corresponding to the audio devices currently connected to the system and meeting the criteria specified in the flags parameter.

Usage

From source file:com.example.android.wearable.speaker.MainActivity.java

/**
 * Determines if the wear device has a built-in speaker and if it is supported. Speaker, even if
 * physically present, is only supported in Android M+ on a wear device..
 *///from  w  w w  .  j ava2s.  c o  m
public final boolean speakerIsSupported() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PackageManager packageManager = getPackageManager();
        // The results from AudioManager.getDevices can't be trusted unless the device
        // advertises FEATURE_AUDIO_OUTPUT.
        if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
            return false;
        }
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        for (AudioDeviceInfo device : devices) {
            if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                return true;
            }
        }
    }
    return false;
}