1

I am writing data to a file that I want to make available to the user via USB i.e. device is connected to PC and the user can pull the file from the device.

My device is a Google Nexus 5 which does not have an SD card. When I connect the Nexus to my PC I can see under Internal Storage the folder Android/data/'package'.

How can I create a directory for my package here?

I have tried using getExternalFilesDir and getExternalStoragePublicDirectory but they only store the data on a temporary emulated SD card that is not visible from the PC (but in Eclipse/DDMS). A similar case did not help.

Update 1 After rebooting my device I was able to see a file under /Android/data/'package'/file. It got there view getExternalFilesDir(null). When I write the data now, then I don't see the immediate update in the Explorer. Do I have to reboot all the time or is there a way to refresh the explorer?

Update 2 It seems that the files are there. I was able to run a SQLite database back up and restore without seeing the files in Windows Explorer. It is still interesting to know what is required so that they are visible without reboot.

Any idea is appreciated.

Mike

Community
  • 1
  • 1
user3460486
  • 508
  • 1
  • 4
  • 14

1 Answers1

1

I have used the following code its working pretty good on nexus 5 and all other devices

File path = getDir();  //call this function in your code

place this below code in your class which returns the directory of path

   private File getDir() {
            File sdDir = Environment.getExternalStoragePublicDirectory(Environment.MainDirectory);
            return new File(sdDir, "yourdirectoryname");
            }
someone
  • 427
  • 2
  • 11
  • I get the error "MainDirectory cannot be resolved or is not a field". Did you define MainDirectory anywhere? – user3460486 Jul 31 '14 at 21:10
  • MainDirectory is the folder name in your USB storage....change it to something like Android or Pictures (any name of the folder present in USB storage) – someone Aug 01 '14 at 13:17