Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to get USB status #38

Closed
realrk95 opened this issue Jan 6, 2021 · 6 comments
Closed

Need to get USB status #38

realrk95 opened this issue Jan 6, 2021 · 6 comments

Comments

@realrk95
Copy link

realrk95 commented Jan 6, 2021

Hi,

I'm trying to create a stream for listening to the USB status (permission allowed/denied, OTG available or not, etc.). Is there any functionality built into this library to check for the same?

here is the sample pseudo code:

class USBStatusMonitor implements ReactiveState<USBStatus> {
  const USBStatusMonitor(this._usb);

  final UsbSerial _usb;

  @override
  Stream<USBStatus> get state => _usb.statusStream;
}

Is this functionality like statusStream or USBStatus available in this library for easy detection of sudden changes from the user (user suddenly disables OTG, OTG is not available on this device etc.)?

@realrk95
Copy link
Author

I couldn't find the functionality in the API reference.

@EParisot
Copy link
Contributor

EParisot commented Jan 21, 2021

Hi, maybe you can just listen to the USB events and get a status from there :

UsbSerial.usbEventStream.listen((UsbEvent msg) async {
    if (msg.event == UsbEvent.ACTION_USB_ATTACHED) {
        // Do something if usb attached
    } else if (msg.event == UsbEvent.ACTION_USB_DETACHED) {
        // Do something else if usb detached
    }
});

If you declared your usb device(s) in android manifest, you will receive events for them...

@realrk95
Copy link
Author

Thanks, this is kind of what I was looking for. What about checking permissions or getting permissions in case the user has denied it? Is there any library which exposed that API?

@EParisot
Copy link
Contributor

Great !
Yes I use https://pub.dev/packages/permission_handler to ask the user about permissions...

@realrk95
Copy link
Author

Thanks m8, this works.

@altera2015
Copy link
Owner

Closing since fixed.

@altera2015 altera2015 reopened this Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants