Reputation: 81
Is there anyway to differentiate different type of audio devices in android? For example, I got audio device type A and audio device type B from different manufacturers, both devices are using audio jack. Whenever user plug in audio device type A or type B, I wanted to know device id or name, type. I can detect the audio devices plug in/ out using BroadcastReceiver. But couldn't get device id or name or type. Scenario is: when audio device type A is connected, start service A, and when audio device type B is connected, start service B.
Upvotes: 1
Views: 1327
Reputation: 6871
No, it's not possible, unfortunately. The audio jack is a purely analog standard, it just doesn't provide any means for identifying a device. The only thing that can be identified is whether it's headphones (no mic), a headset (with mic), or a line in (has higher input impedance than headphones). And the latter difference isn't actually communicated to apps, it only affects how Android does audio routing and applies volume settings.
For USB and Bluetooth devices, information about device manufacturer and ID is available, so they can be distinguished but you need to use a lower level API than just a broadcast receiver. See https://developer.android.com/guide/topics/connectivity/usb/host.html and https://developer.android.com/guide/topics/connectivity/bluetooth.html.
Upvotes: 2