1

everybody!

I create a file in my android app with this code, run in UI thread:

final File dir = Environment.getExternalStorageDirectory();
final File file = new File(dir, "file" + System.currentTimeMillis()); //$NON-NLS-1$

try
{
   file.createNewFile())
}

catch (Exception e)
{
   ...
}

and I can't see it on my Win7 PC, until I rename the file on the phone with the file browser. I run the program on Samsung Galaxy Nexus, OS ver 4.0.2. What might be wrong?

Thanks.

RobinBobin
  • 555
  • 7
  • 17
  • With an android 4.0.2 device you are probably running into the MTP / emulated external storage behavior, and probably have a file browser that knows to handle that - see for example http://stackoverflow.com/questions/10643476/sdcard-content-exist-but-cant-see-them – Chris Stratton Jun 23 '12 at 02:10
  • Why you are not giving any file extension – Vipul Jun 23 '12 at 03:07
  • Thanks a lot for the post, Chris! Yes, MTP is used. I added `MediaScannerConnection.scanFile(getActivity(), new String[] {path}, null, this);` but it didn't solve the problem. The callback gets called, and both params seem to be ok: `path = /mnt/sdcard/Android/data//files` and `uri = content://media/external/file/2014`. The file doesn't appear in Win Explorer until I somehow rename it, though. BTW, I added the ".txt" extension, but it didn't help either. – RobinBobin Jun 23 '12 at 10:54

2 Answers2

2

At last!

The solution is to use MediaScannerConnection.scanFile(context, new String[] {path}, null, null);, but path must include THE NAME OF THE FILE, not only the path. No extension is necessary.

At least, it worked in my case :) .

Huge thanks to Chris Stratton.

RobinBobin
  • 555
  • 7
  • 17
0

The only solution I have found yet, is install SSHDroid on the device and WinSCP on Win7.

RobinBobin
  • 555
  • 7
  • 17