Android USB Host mode service - Start based on USB_DEVICE_ATTACHED

后端 未结 3 1102
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-10 03:21

I want to write a service in Android which starts based on USB_DEVICE_ATTACHED intent. So, basically my service should start when a specific USB Device(FT232C - VID:PID 0403:601

3条回答
  •  醉梦人生
    2021-02-10 04:15

    From my experience a cannot receive the USB intents. I overcame this by creating a hidden activity to receive the intent and re-broadcast it. Of course this activity could also handle starting/stopping your service.

    I have already put up some working code here:
    https://stackoverflow.com/a/15151075/588476
    You will just have to change it so it starts and stops your service automatically.

提交回复
热议问题