本文整理汇总了Java中android.media.AudioManager.getDevices方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.getDevices方法的具体用法?Java AudioManager.getDevices怎么用?Java AudioManager.getDevices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.getDevices方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasSpeacker
import android.media.AudioManager; //导入方法依赖的package包/类
/**
* Used to get if the device has a speacker
* @return
*/
public boolean hasSpeacker()
{
PackageManager packageManager = this.getPackageManager();
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
// Check whether the device has a speaker.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check FEATURE_AUDIO_OUTPUT to guard against false positives.
if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
return false;
}
AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
for (AudioDeviceInfo device : devices) {
if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
return true;
}
}
}
return false;
}
示例2: findAudioDevice
import android.media.AudioManager; //导入方法依赖的package包/类
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
for (AudioDeviceInfo adi : adis) {
if (adi.getType() == deviceType) {
return adi;
}
}
return null;
}