Example usage for android.media AudioDeviceInfo TYPE_BUILTIN_SPEAKER

List of usage examples for android.media AudioDeviceInfo TYPE_BUILTIN_SPEAKER

Introduction

In this page you can find the example usage for android.media AudioDeviceInfo TYPE_BUILTIN_SPEAKER.

Prototype

int TYPE_BUILTIN_SPEAKER

To view the source code for android.media AudioDeviceInfo TYPE_BUILTIN_SPEAKER.

Click Source Link

Document

A device type describing the speaker system (i.e.

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..
 *///w  w  w.j a va  2s .com
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;
}