Skip to content

Instantly share code, notes, and snippets.

@Ochornma
Created December 27, 2019 11:10
Show Gist options
  • Select an option

  • Save Ochornma/cafe1af1eb941d7e7c182278ffdf4b78 to your computer and use it in GitHub Desktop.

Select an option

Save Ochornma/cafe1af1eb941d7e7c182278ffdf4b78 to your computer and use it in GitHub Desktop.
Checking for speaker support on WearOS.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment