Files showing as empty on PC but non-empty on Smartphone

robguinness picture robguinness · Jul 22, 2013 · Viewed 34.2k times · Source

I'm having a weird problem with my Samsung Galaxy Nexus, where files created and written to in my application are displaying fine when accessed on the phone itself (via ES File Explorer), but when I try to view the same files on my PC (with phone connected via USB), they show up as having 0 bytes (and empty when opened).

These should be normal text files, which I am creating using new File(dir, filename) and writing to using the write method of PrintWriter. I'm also adding the new files to the content database using MediaScannerConnection.scanFile.

I've used basically the same code in previous applications (>6 months ago) without any issues, so I'm really confused as to why it's not working now. Has anyone had similar problems?

UPDATE:

Still trouble-shooting this...two more observations have me utterly confused:

  1. I tried accessing the same files on another PC, and they worked fine. This had me thinking it could be some driver issue, but that would still be odd because I haven't changed the driver at all (I never experienced this issue earlier).

  2. I tried creating files using a different application that I previously created. It uses basically the same FileIO class for file creation, etc. No such issues experienced with this application.

Answer

Vikram picture Vikram · Jul 22, 2013

I faced the same issue. This has to do with how MTP (Media Transfer Protocol) is defined.

MTP has a few drawbacks. Wikipedia lists them as :

  1. When opening a file, the user must wait till the file has copied to the PC before it can be viewed. (Note: The file remains on the PC hard drive after viewing and the device is removed)
  2. No creation of files on the device from the PC, files must be created on the PC and copied over.
  3. No editing of files on the device, files must be copied off the device before edits can be saved and file copied back.

In my case, screen caps I took while the phone was connected through usb came out to be 0 kb in size(on PC). But, unplugging and plugging the usb solved this.