Example usage for android.media AudioDeviceInfo getType

List of usage examples for android.media AudioDeviceInfo getType

Introduction

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

Prototype

public int getType() 

Source Link

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 ww.ja  v  a 2s . 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;
}