Java Code Examples for android.media.AudioDeviceInfo#getType()

The following examples show how to use android.media.AudioDeviceInfo#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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..
 */
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;
}
 
Example 2
Source File: FlutterIncallManagerPlugin.java    From flutter-incall-manager with ISC License 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example 3
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example 4
Source File: HeadsetTracker.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
HeadsetTracker(Context context, HeadsetUSourceData data,
               @NonNull PendingIntent event_positive,
               @NonNull PendingIntent event_negative) {
    super(context, data, event_positive, event_negative);

    boolean plugged_in = false;
    Boolean has_microphone = null;

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        AudioDeviceInfo[] audioDevices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        for (AudioDeviceInfo deviceInfo : audioDevices) {
            if (deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
                    || deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                plugged_in = true;
                has_microphone = deviceInfo.isSource();
            }
        }
    } else {
        plugged_in = audioManager.isWiredHeadsetOn();
    }
    Boolean match = determine_match(data, plugged_in, has_microphone);
    newSatisfiedState(match);
}
 
Example 5
Source File: AppRTCAudioManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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(Config.LOGTAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(Config.LOGTAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
 
Example 6
Source File: AppRTCAudioManager.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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(Config.LOGTAG, "hasWiredHeadset: found wired headset");
                return true;
            } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) {
                Log.d(Config.LOGTAG, "hasWiredHeadset: found USB audio device");
                return true;
            }
        }
        return false;
    }
}
 
Example 7
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: AssistantActivity.java    From sample-googleassistant with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: HeadphoneStateMonitor.java    From talkback with Apache License 2.0 5 votes vote down vote up
private static boolean isExternalDevice(AudioDeviceInfo device) {
  return device.isSink()
      && (device.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP
          || device.getType() == AudioDeviceInfo.TYPE_AUX_LINE
          || device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
          || device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET
          || device.getType() == AudioDeviceInfo.TYPE_USB_HEADSET);
}