List of usage examples for android.media AudioManager getDevices
public AudioDeviceInfo[] getDevices(int flags)
flags
parameter. 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; }