Sachin J
Sachin J

Reputation: 2201

Hardware interrupt API for Linux

When I am going to connect device through USB port, I want to detect it immediately. I am searching for a Java API, my main target is Linux OS.

Does anyone know an API like that?

Upvotes: 1

Views: 242

Answers (2)

Raber
Raber

Reputation: 2080

would also consider monitoring USB events by DBus interface

there is DBus-Java library here and a similar thread but on python here

Upvotes: 0

CAMOBAP
CAMOBAP

Reputation: 5657

You can do something like this:

try {
    String command = "lsusb"; // you may add some param if you want
                              // or use adb for instance
    Process child = Runtime.getRuntime().exec(command);

    // Get output stream to write from it
    OutputStream out = child.getOutputStream();

    // TODO parsing lsusb output

    out.close();
} catch (IOException e) {
}

Upvotes: 1

Related Questions