Java: list of cameras connected to the network

My program is currently File.listRoots() list of drives connected to my computer with File.listRoots() . But, when I connect the camera or MP3 player to the computer directly (instead of inserting a memory card), it is not listed and does not have a drive letter in Windows Explorer. For example, here is the location of my camera:

 Computer\Canon PowerShot SD750\Removable storage 

How can I also list cameras / other devices that do not have a drive letter? I assume that this will require the JNI library, but I donโ€™t know for sure.

Thanks!

PS Out of desperation, I tried to list the contents of Computer\ ; that didn't work of course.


Update . I found this question here: The portable device path in Windows ; what exactly is the problem I have, but there is no solution.

+6
source share
4 answers

Java 7 has several promising classes in this area, for example: http://download.java.net/jdk7/docs/api/java/nio/file/FileSystem.html

Assuming you need to work in Java 6 as well, I would suggest running a shell script and analyzing its output. On Windows, you can run mountvol, on Unix / MacOS X mount, etc. Of course, parsing the output will be a little tedious, and you have to worry about every OS the application runs on, but at least ... I donโ€™t know what .... does it work?

Here is an example of code that seems useful on Windows:

 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume") For Each objItem In colItems WScript.Echo "Automount: " & objItem.Automount WScript.Echo "Block Size: " & objItem.BlockSize WScript.Echo "Capacity: " & objItem.Capacity WScript.Echo "Caption: " & objItem.Caption WScript.Echo "Compressed: " & objItem.Compressed WScript.Echo "Device ID: " & objItem.DeviceID WScript.Echo "Dirty Bit Set: " & objItem.DirtyBitSet WScript.Echo "Drive Letter: " & objItem.DriveLetter WScript.Echo "Drive Type: " & objItem.DriveType WScript.Echo "File System: " & objItem.FileSystem WScript.Echo "Free Space: " & objItem.FreeSpace WScript.Echo "Indexing Enabled: " & objItem.IndexingEnabled WScript.Echo "Label: " & objItem.Label WScript.Echo "Maximum File Name Length: " & objItem.MaximumFileNameLength WScript.Echo "Name: " & objItem.Name WScript.Echo "Quotas Enabled: " & objItem.QuotasEnabled WScript.Echo "Quotas Incomplete: " & objItem.QuotasIncomplete WScript.Echo "Quotas Rebuilding: " & objItem.QuotasRebuilding WScript.Echo "Serial Number: " & objItem.SerialNumber WScript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas WScript.Echo "Supports File-Based Compression: " & _ objItem.SupportsFileBasedCompression WScript.Echo Next 

Here is the result I got for my e-book reader:

 Automount: True Block Size: 4096 Capacity: 999120896 Caption: G:\ Compressed: Device ID: \\?\Volume{8e3b4ce5-a124-11e0-9d2b-e30c5839642d}\ Dirty Bit Set: False Drive Letter: G: Drive Type: 2 File System: FAT32 Free Space: 663683072 Indexing Enabled: Label: PocketBook9 Maximum File Name Length: 255 Name: G:\ Quotas Enabled: Quotas Incomplete: Quotas Rebuilding: Serial Number: 1276177233 Supports Disk Quotas: False Supports File-Based Compression: False 
+2
source

Solving the above problem using the JMTP library on

  http://code.google.com/p/jmtp/ 

Here is my code

  package jmtp;

 import be.derycke.pieter.com.COMException; import be.derycke.pieter.com.Guid; import java.io.*; import java.math.BigInteger; import jmtp.PortableDevice; import jmtp.*; public class Jmtp { public static void main(String[] args) { PortableDeviceManager manager = new PortableDeviceManager(); PortableDevice device = manager.getDevices()[0]; // Connect to my mp3-player 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()) { // // BigInteger bigInteger1 = new BigInteger("123456789"); // File file = new File("c:/JavaAppletSigningGuide.pdf"); // try { // storage.addAudioObject(file, "jj", "jj", bigInteger1); // } catch (Exception e) { // //System.out.println("Exception e = " + e); // } // System.out.println(o2.getOriginalFileName()); } } } manager.getDevices()[0].close(); } } 

Remember to add jmtp.dll files (which come with jmtp download) as a native library for more information see my answer to
  http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans 
+1
source

This may not be the answer you are looking for, but assigns them a drive letter, not an option? Typically, you can manually do this using USB devices in Windows using My Computer> right-click> Manage> Storage.

Perhaps the CaptureDeviceManager in JMF (java media framework) can help you, but I doubt it.

0
source

Perhaps you can take a look at the Morena Framework http://www.gnome.sk/Twain/jtp.htmlv (it seems open source, but a bit more expensive, although there is a free evaluation version) for a list of connected devices for TWAIN compatible scanners / cameras (Windows / MAC) or compatible with SANE (Linux or other unix flavor), you can do this:

 import SK.gnome.morena.*; import SK.gnome.twain.*; public class Test { public static void main(String[] args) throws Exception { TwainSource[] sources=TwainManager.listSources(); if(sources == null) return; for(int i = 0; i < sources.length; i++) { System.out.println("Twain source is: " + ts.toString()); } } } 

Maybe this can help, if not I think, maybe JMF is a possible solution.

0
source

Source: https://habr.com/ru/post/891492/


All Articles