USB events
2 min
In order to trigger events when the device is plugged in, use the following callback in your mainActivity:
override fun onDeviceAttach() {
super.onDeviceAttach()
//add function here
}In order to trigger an event when the device is unplugged use the following callback in your mainActivity:
override fun onDeviceDetach() {
super.onDeviceDetach()
//add function here
}
here's an example of a Snackbar UI feedback triggered by USB events:
override fun onDeviceAttach() {
super.onDeviceAttach()
Snackbar.make(
findViewById<UVCCameraTextureView>(R.id.camera_view),
"Device Attached",
Snackbar.LENGTH_LONG
).show()
}
override fun onDeviceDetach() {
super.onDeviceDetach()
Snackbar.make(
findViewById<UVCCameraTextureView>(R.id.camera_view),
"Device Detached",
Snackbar.LENGTH_LONG
).show()
}