android - 我如何从假装成微型电话的USB加速度传感器获取数据?

标签 android audio usb sensor microphone

这是我的第一个应用,我正在尝试从传感器获取数据。
该传感器为Digiducer,根据其网站,它使用通用USB音频驱动程序。

No drivers or DLL’s required! USB Audio drivers are standard in most operating systems (iOS, Windows, MacOS, Android) LINK



我读过USB Digital Audio Article,它说如果该设备符合类要求(它声称是这样),则不需要安装任何特定的驱动程序。

The term driverless is a common synonym for class compliant, indicating that it is possible to use the standard features of such a peripheral without requiring an operating-system specific driver to be installed. LINK



我检查了Android support for USB audio class一章中提到的所有条件,并且传感器与它们完全匹配

Android 5.0 (API level 21) and above supports a subset of USB audio class 1 (UAC1) features:
- The Android device must act as host
- The audio format must be PCM (interface type I)
- The bit depth must be 16-bits, 24-bits, or 32-bits where 24 bits of useful audio data are left-justified within the most significant bits of the 32-bit word
- The sample rate must be either 48, 44.1, 32, 24, 22.05, 16, 12, 11.025, or 8 kHz
- The channel count must be 1 (mono) or 2 (stereo)



我不知道该怎么做才能从传感器获取数据。

最佳答案

我自己弄清楚了。
其实我什么也没做。
我只需要调用AudioManager并在输入设备中搜索设备名称

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    AudioDeviceInfo[] adiArray = am.getDevices(1); // INPUT_DEVICES = 1

    for (AudioDeviceInfo deviceInfo : adiArray) {
        String name = deviceInfo.getProductName().toString().toLowerCase();
        if (name.contains("33d01")) {
            externalMic = deviceInfo;
            break;
        }
    }

关于android - 我如何从假装成微型电话的USB加速度传感器获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58979003/

相关文章:

java - 如何使用java代码获取USB驱动器序列号或元数据

java - 在不同类android中访问变量的最佳方法

java - MediaController 方法 adjustmentVolume 和 MediaSession

debugging - 如何在 Sony Xperia Z1 上启用 USB 调试

c# - Xamarin SimpleAudioPlayer返回System.NullReferenceException

audio - 如何使用音频文件作为输入实现单边带抑制载波调制?

android - 开发人员使用哪些 Android 平板电脑来编写和测试 USB 主机应用程序?

android - 在 Android 中用于跟踪目的的网络位置与 GPS 位置

android - 如何根据时间查看昼夜循环?

java - 在 Android 中使用 .contains() 关键字的字符串匹配