Use of jmtp.jar to find portable devices attatched to linux OS

903 views Asked by At

I want to monitor portable devices attached to my linux OS using jmtp.jar. Below is the code that i am using to do the same. It's working fine in Windows but when i run this code it gives me "Not supported OS exception". do jmtp.jar support linux OS? If not then any alternative solution for linux OS?

Code that i used

import java.io.*;
import java.math.BigInteger;
import jmtp.PortableDevice;
import jmtp.PortableDeviceManager;
import jmtp.PortableDeviceObject;
import jmtp.PortableDeviceStorageObject;

public class Jmtp {

public static void main(String[] args) {
    PortableDeviceManager manager = new PortableDeviceManager();
    PortableDevice device = manager.getDevices()[0];
    device.open();

    System.out.println(device.getModel());

    System.out.println("---------------");

    // Iterate over deviceObjects
    for (PortableDeviceObject object : device.getRootObjects()) {
        // If the object is a storage object
        if (object instanceof PortableDeviceStorageObject) {
            PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;

            for (PortableDeviceObject o2 : storage.getChildObjects()) {
                System.out.println(o2.getOriginalFileName());
            }
         }
      }
    manager.getDevices()[0].close();
    }
 }

Exception that i got :

Exception in thread "main" java.lang.RuntimeException: not supported os
    at jmtp.PortableDeviceManager.<init>(PortableDeviceManager.java:37)
    at find_usb.Jmtp.main(Jmtp.java:24) 
1

There are 1 answers

1
nablex On

Google states:

A project aimed at allowing java programs to access MTP compabitble portable 
media players. The main target is currently windows, by wrapping the WPD api, 
but design decisions have been made to support both linux and mac os x in 
the future with the same API. For more information, please see the wiki.