How can you access USB from cross-platform Java? - java

I need to copy some files from a PC into a pen drive. I visited JUSB package description, but it is only for windows. So, is there any easy and platform independent way to copy files from computer to USB drive using Java?

You don't need to worry about the fact that it's a USB drive; when the user inserts the device it is recognized by the OS and shows up as a mounted drive in your filesystem. Then you can just use java.io.File and friends to access it. Additional tip: use org.apache.commons.io.FileUtils as a handy toolkit to make many common file-related tasks easier.
If you need to detect the new USB device automatically in Java, that's a bit tricky. See this question.

You can take a look at libUsb Java Bindings a javabinding for libUsb. Btw. the jUSB API seems to support Linux too (package: usb.linux), maybe this article can help you: Access USB devices from Java applications

Related

Programmatically write to an android device

I would like to write a program in java that copies mp3 files from my PC, renames them so they sort correctly, and transfers them to the sdCard on my Android phone via USB. I assumed this would be a trivial task since I have already successfully written a similar program for transferring files to an external HDD, however I reached an immediate stumbling block. It seems that java (and indeed other desktop applications) cannot locate the device's file system even when given the exact path that windows explorer reports (This PC\SAMSUNG-SM-G900V\Card).
I've tried researching and the problem seems to have to do with the device being considered a Portable Device rather than a drive (maybe) but I have not found a concrete solution. An answer to the following question seems to suggest it is impossible but I find that hard to believe.
Can Android's internal memory be mapped to a drive letter on PC?
Does anyone know of a way to access Portable Device storage through java? If if it indeed impossible, can someone perhaps help me understand why it is possible through Windows Explorer but not through other programs.

How to share files to Airstash programmatically?

i'm android software developer, i want to share files to Airstash programmatially without open the Airstash+ application. is there any sdk available for android? please give me any suggestion.
AirStash is also a WebDAV server (also uses http streaming). You can use this standard to access folders & files, create/delete folders & files (rename and move is on the way--see AirStash on Facebook). There are many 3rd party apps that access AirStash utilizing this method.
Recently purchased a RAVPower® FileHub and its great value really worth the money. Main reason was that it is a simple and reliable product with a SD card slot and USB port to connect a multitude of different storage devices. It acts as both a router with the ability to bridge my home or business to access to the internet, and as a device you can add storage devices some external storage for my documents. All these it works great. Wish I would find this before cause it really a MUST.Besides, its 3000Amh external battery help my smartphone a lot when I am outing! It priced only $49.99 makes it more attractive!

how to capture a video from /dev port in linux using java

i am trying to capture video from my /dev/video1 usb camera using java, i was wondering as to how to actually do this? my project is supposed to capture the video and stream it to another computer. is it also possible to set up an avconv server using java?
Java does not have an extensive support for media. You can use GStreamer JNI bindings for this or switch to QT or native C/C++ GStreamer.
It's already been done for you so you might take a look into the existing projects.
v4l4j wouble be a great place to start.
update
As Andy Ross commented the library I linked is very low level and you may be looking into something more easy to use as gstreamer-java.

Make a USB Device, Control It In Java

I'm thinking about making a physical controller (device?) with knobs, buttons, and LEDs. I'd like to interact with it using Java (respond to the knobs, light up LEDs, etc). The reason I mention Java is two-fold: first, I know Java well1. Second, I've written the rest of the program I need to interface with in Java (though there are ways to talk to the Java program from another language).
I would like the device to connect via USB and be (computer-)platform independent.
I haven't the slightest idea of where to start, except to start reading the Arduino website. Is this my best/only option? Is there something better suited for communicating with Java?
Note: I know that Arduino has something to do with Java (not sure what), but it seems like code must be written in a subset of C.
How would I get moving on this topic?
1 - No laughter, please.
The Arduino development environment is written in Java.
But the standard language you write a program for the Arduino platform is effectively C++.
The Arduino platform is based on an Atmel AVR chip. There is at least one Java VM for AVR chips. There are other languages available for the AVR such as Forth and BASIC (although I could only find commercial versions, so I'll if you want to find them, search for "AVR BASIC").
The Arduino uses a virtual COM port to communicate between the host computer and it. A virtual COM port emulates an old style serial line but is done with USB. You can use the Java communication API to then have a Java program running on the host computer communicate with your physical device.
For some encoders and buttons, you probably want to implement a USB HID device. If you're going to produce more than a couple of them, you'll want to do a custom board. Check out V-USB, an open-source library for making USB HID devices using Atmel microcontrollers. They have a bunch of examples of projects that use this library.
You could probably make this look like a HID joystick, using the encoders to produce X/Y axis information and having the buttons act like buttons. They you could use standard Java gaming APIs to read the joystick values.
Can you expand on your need for a custom device? It seems to me that designing hardware has a pretty high barrier to entry and that most applications I can think of would be better resolved by repurposing an existing piece of game controller hardware. If you really need new hardware, then i suggest you start by googling 'USB development kit' or
'USB development board' which will get you links like this, this and this.
As for working with USB hardware from Java, I've played around with the JUSB library a bit and it looks promising, but appears to be limited to Linux only because the Windows version of the native library half of the library hasn't been written. Alternatives can by found by googling 'HID java'.
Ok, computer-platform independant? What platforms are you targetting? That would depend on the driver and support for that said platform, what does the usb device do? Is it a mass storage device...You may have to look around and see if you can find a device driver that can talk to the device...
Hope this helps,
Best regards,
Tom.
I know for the serial port there were libraries that existed for interacting with it (rs232 library). Googling for java and USB returned several answers (the first was called jUSB). That would be the first type of thing I would be looking for.
sample for java usb connection to freescale microcontroller:
http://javausbapi.blogspot.com/

Accessing Windows Mobile device Storage Card from Java?

I'd like to be able to access the contents of my Storage Card which is in my Windows Mobile device. Normally, I'd just remove the card and shove it in a card reader, but its encrypted (and thus, locked to my WM device).
Is there an API or some sort of framework allowing read/write access to the Storage Card (while PDA is docked to PC)?
Reason is: I'm sick of having to create playlists for each album every time I upload to it. I'd like to automate this process.
Any pointers would be greatly appreciated.
When the PDA is connected to the PC you can use RAPI to access files, registry etc on a Windows Mobile device, but I don't know of a Java interface to it. Should be a piece of cake with JNI though... :-)
RAPI (Remote API) is used for accessing the WM device from the desktop, and can be used to access files.
See RAPI and CeCreateFile, or this tutorial on RAPI.
You can point it to files on the storage card by the "\Storage Card\" path.
But, as you notice, this is a C++ API... I'm not aware of any RAPI wrappers for Java, unfortunately.

Categories

Resources