0% found this document useful (0 votes)
33 views

4GitHub - Magnusja - Libaums - Open Source Library To Access USB Mass Storage Devices On Android Without Rooting Your Device

Uploaded by

mobisectester
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

4GitHub - Magnusja - Libaums - Open Source Library To Access USB Mass Storage Devices On Android Without Rooting Your Device

Uploaded by

mobisectester
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Troubleshooting

If you get the following error fairly often (mostly under Android 9.0 Pie):

java.io.IOException: Could not write to device, result == -1 errno 0 null

or something similar, you might want to try the libusb module. This uses, instead of the Android USB host API, the libusb library for low
level communication with the USB mass storage device.

see discussions: #209 #237 #242

Note, that libusb is licensed under LGPL, which is different from the license this project is licensed under! This might come with some
drawbacks or extra work for closed source applications, see here: https://xebia.com/blog/the-lgpl-on-android/

Provide access to external apps


Usually third party apps do not have access to the files on a mass storage device if the Android system does mount (this is usually
supported on newer devices, back in 2014 there was no support for that) the device or this app integrates this library itself. To solve this
issue there are two additional modules to provide access to other app. One uses the Storage Access Framework feature of Android
(API level >= 19) and the other one spins up an HTTP server to allow downloading or streaming of videos or images for instance.

HTTP server
javadoc 0.6.2

libaums currently supports two different HTTP server libraries.

1. NanoHTTPD
2. AsyncHttpServer

You can spin up a server pretty easy, you just have to decide for a HTTP server implementation. If you do not have special
requirements, you can just go for one, it should not make much of a difference.

Java

UsbFile file = ... // can be directory or file

HttpServer server = AsyncHttpServer(8000); // port 8000


// or
HttpServer server = NanoHttpdServer(8000); // port 8000

UsbFileHttpServer fileServer = new UsbFileHttpServer(file, server);


fileServer.start();

Kotlin

val file: UsbFile


// can be directory or file

val server = AsyncHttpServer(8000) // port 8000


// or
val server = NanoHttpdServer(8000) // port 8000

val fileServer = UsbFileHttpServer(file, server)


fileServer.start()

The file you provide can either be an actual file or a directory:

1. File: Accessible either via "/" or "/FILE_NAME"


2. Directory: All files in this directory und sub directories are accessable via their names. Directory listing is not supported!

If you want to be able to access these files when your app is in background, you should implement a service for that. There is an
example available in the httpserver module. You can use it, but should subclass it or create your own to adapt it to your needs.

Java

You might also like