简体   繁体   中英

Can't find folder or file created with Android App with windows file exlorer

I'm creating a directory and a text file on the sdcard in one of my apps because I want to be able to move it to my computer for analysis. But I can't find the folder or the file I'm creating on my sdcard using the file browser on my computer. I CAN find and read the file using my phones file manager but not using the file browser in windows. So the file and folder are succesfully created and I can write to the file, I can also find and read the file using the file manager on my phone but I can't find either directory or file using my computer.

I have a uses permission for the application to allow it to write to external storage.

This is the code I use to create the file and directory.

String fileName = "testFil.txt";
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/PulsApp";

File appDirectory = new File(path);
appDirectory.mkdirs();
File file = new File(path, fileName);

try {
    file.createNewFile();
} catch (IOException e) {
}

Does anyone know what the problem is and how to fix it? I really need to be able to write files to my sdcard so I can transfer them to my computer.

I am completely baffled by this problem since all the research I've done point to that everyone else is doing the same thing.

If your device is running Android 3.0 or higher, you also need to use MediaScannerConnection to index your newly-created file before it will show up on a development PC's file explorer.

More accurately, the newly-created file needs to be indexed by the MediaStore . That will eventually happen for other reasons (eg, device reboot). However, you are better served using scanFile() on MediaScannerConnection to get it to happen more quickly.

I blogged about this last summer .

Sometimes that the MediaScannerConnection will recognize the folder as a unknown type file, so try to create another folder inside the original one can avoid this problem. I have met the same problem, and I use the method in the comment

And it works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM