frenchone
frenchone

Reputation: 1597

Can I launch a specific app when android device get physically connected to a specific usb device?

Can I "register" a (already installed) specific app to be launched when android device get physically connected to a specific usb device ?

Eg.
I connect a keyboard (of a certain brand or with a special USBid/class) and it automatically launch a text editor app
I connect an USB soundcard and it launches an audio app.

And "better", is there an autolaunch on Android ? I plug a keyboard+storage device to my smartphone and Android will ask me if I want to install the apk from the storage (or download it from predefined url)
Obviously for security reasons I understand installing the app from the storage will need confirmation by user. But, once the app has been "registered" would it be possible to launch the app automatically without having a confirmation screen ?

I know I could get USB info with android.hardware.usb.usbdevice. My question is more about how I can tell Android to launch this app rather than another when usb device is connected.

Upvotes: 1

Views: 2149

Answers (1)

aaroncio
aaroncio

Reputation: 307

I think you could register your app to receive a system broadcast like USB_ACCESSORY_ATTACHED and make the logic to launch your app when this happens.

Check https://developer.android.com/guide/components/broadcasts

https://developer.android.com/reference/android/hardware/usb/UsbManager.html#ACTION_USB_DEVICE_ATTACHED

Upvotes: 2

Related Questions