Android USB Host mode service - Start based on USB_DEVICE_ATTACHED

后端 未结 3 732
一个人的身影
一个人的身影 2021-02-10 03:20

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 03:52

    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.

提交回复
热议问题