How to read files from usb flash drive using libusb libarary api's?
I want to read files from usb device and I read somewhere that I've to use libusb library for it.
Now using libusb api's I'm able to obtain the device handle and open it, But how do I read certain files from it and provide those files info to my Qt application?
@Ronak5 There is absolutely no need for libusb to read/write files from/to USB flash drive.
On Windows such a drive is mounted as a drive with its own drive letter. On Linux MacOS it is mounted somewhere in the file system (like /media/SUB_DRIVE). Just access it in the same way you do with an internal drive.
@Ronak5 is this on android ?
Because if it is, than neither Qt nor libusb will help you here. Android strictly prohibits access to external sdcard and/or usb devices.
You'll have to use native java-api for this.
@jsulm okay. But everytime the drive name while reading from /media/drive
will be different. How do I obtain the inserted usb name? Also do I have to take care of permission also?
@J.Hilk Hi, yes I also need to do this on android. So I've to use java-api to read those and extract the info in Qt app?
Do you have any reference/ example to read about it? Thanks.
@Ronak5 Permissions is something handled by the OS/filesystem, not USB.
Regarding drive letter: I'm not sure what your use case is and what exactly you're doing. You can enumerate the drive letter using Qt, see https://doc.qt.io/qt-5/qstorageinfo.html
this should help further:
@jsulm I intend to read the music and video format files from an usb device inserted and play those files. I'm able to play it on hard coding with the usb mounted name in /media. But I intend to make it generic without hard coding the mount name available in /media drive.
@J.Hilk thanks for help.
@jsulm hey, QStorageInfo is what helped me to get the mounted storage devices name. Thanks a lot for hints.
@J.Hilk Hi, I was going through lib usb for android here https://libusb.info/
It says that "It is portable: Using a single cross-platform API, it provides access to USB devices on Linux, OS X, Windows, Android, OpenBSD, etc."
So , does it mean the linux implementation would work for android platform also?
I don't know how to include libusb libraries for android platform.