0

So I create a file in my app in a directory, i want to be able to get the file from my tablet by just connecting it to my laptop and getting the file from the directory but am having trouble. I remember reading somewhere that you have to restart your device and the file just magically appears in the directory and it worked! I don't want to have to restart my device every time, is there any way around this?

File emulatedStorage = Environment.getExternalStorageDirectory();
File directory = new File(emulatedStorage.getAbsolutePath()+"/logger");

//check if directory exists.
if(!directory.exists()){
directory.mkdirs();
}
//make file and write stuff to it etc...

so like I said the file shows up when i restart my tablet, any suggestions or explanations?

sergio
  • 75
  • 2
  • 10
  • Then you have to invoke mediascanner on the newly created file first. It's just one code line. I don't know it from head. So just google this site for it. You are not the first with this problem. – greenapps Sep 11 '14 at 06:47
  • http://stackoverflow.com/questions/25780945/after-saved-image-cant-see-it-in-gallery-android – greenapps Sep 11 '14 at 07:04
  • Awesome! Mediascanner is exactly what I was looking for, thanks alot! I found an example online and it worked. – sergio Sep 11 '14 at 14:59

2 Answers2

0

You could use adb. There's the "adb pull /data/local/tmp/filename" command, instead of adb pull you can just add your file path. The nicest thing might be a shell script including a while true loop. First add " adb wait-for-device" then "adb pull pathOnTheDevice" && play okSound, and in the last line a sleep 5.

This would allow you to just plug in your device and it would automatically transfer the files, playing ok when done. After that you will have 5 seconds to pull it off, otherwise transfer will start again.

You could give adb pull two arguments, the second path could be the local place where you want your files to be on your pc.

Or did I got it wrong? Do you want to transfer files the other way round? There is adb push, working the same way.

Good luck!

user3387542
  • 611
  • 1
  • 8
  • 28
0

Try this:

File directory = new File (Environment.getExternalStorageDirectory().toString() 
                           + File.separator + logger);
directory.mkdirs(); // check if already existing
File file = new File (directory, "yourFileName");

And then you do whatever you wanna do with that file.