Java 类android.media.AudioDeviceInfo 实例源码

项目:nc-android-webrtcpeer    文件:RTCAudioManager.java   
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return audioManager.isWiredHeadsetOn();
    } else {
        final AudioDeviceInfo[] devices = audioManager.getDevices(android.media.AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo device : devices) {
            final int type = device.getType();
            if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                Log.d(TAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(TAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
项目:AppRTC-Android    文件:AppRTCAudioManager.java   
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    return audioManager.isWiredHeadsetOn();
  } else {
    final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
    for (AudioDeviceInfo device : devices) {
      final int type = device.getType();
      if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
        Log.d(TAG, "hasWiredHeadset: found wired headset");
        return true;
      } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
        Log.d(TAG, "hasWiredHeadset: found USB audio device");
        return true;
      }
    }
    return false;
  }
}
项目:Android_watch_magpie    文件:MainActivity.java   
/**
     * 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;
    }
项目:react-native-incall-manager    文件:InCallManagerModule.java   
/**
 * Checks whether a wired headset is connected or not.
 * This is not a valid indication that audio playback is actually over
 * the wired headset as audio routing depends on other conditions. We
 * only use it as an early indicator (during initialization) of an attached
 * wired headset.
 */
@Deprecated
private boolean hasWiredHeadset() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return audioManager.isWiredHeadsetOn();
    } else {
        final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo device : devices) {
            final int type = device.getType();
            if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                Log.d(TAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(TAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
项目:GmsWear    文件:WearUtil.java   
/**
 * Determines if the wear device has a built-in speaker or not.
 * <p>
 * <p><b>Important: </b>This method should only be called on a wear device; the return value on
 * a non-wear device can be trusted if and only if the device is running  android version M+.
 */
public static final boolean wearHasSpeaker(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PackageManager packageManager = context.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) context
                .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;

}
项目:androidthings-googleassistant    文件:AssistantActivity.java   
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;
}
项目:androidthings-googleassistant    文件:AssistantActivity.java   
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;
}
项目:androidthings-googleassistant    文件:AssistantActivity.java   
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;
}
项目:sample-googleassistant    文件:AssistantActivity.java   
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;
}
项目:sample-googleassistant    文件:EmbeddedAssistant.java   
/**
 * Sets a preferred {@link AudioDeviceInfo} device for input.
 *
 * @param device The preferred audio device to acquire audio from.
 * @return Returns this builder to allow for chaining.
 */
public Builder setAudioInputDevice(AudioDeviceInfo device) {
    mEmbeddedAssistant.mAudioInputDevice = device;
    return this;
}
项目:sample-googleassistant    文件:EmbeddedAssistant.java   
/**
 * Sets a preferred {@link AudioDeviceInfo} device for output.
 *
 * param device The preferred audio device to route audio to.
 * @return Returns this builder to allow for chaining.
 */
public Builder setAudioOutputDevice(AudioDeviceInfo device) {
    mEmbeddedAssistant.mAudioOutputDevice = device;
    return this;
}