When I create a file in my app on the SD card it is visible in a file manager like ES Explorer.
However, it is not visible when the device is connected to the computer until the file is renamed in the file manager. Then it promptly becomes visible. This happens on a Nexus 4. Is there an error in my code or some other quirk I'm experiencing?
// Mostly from http://stackoverflow.com/a/2661882/572635
public void exportDatabaseFile() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
String dbPath = "/data/my.app/databases/db.db";
FileChannel src = new FileInputStream(new File(data, dbPath)).getChannel();
FileChannel dest = new FileOutputStream(new File(sd, "db.db")).getChannel();
dest.transferFrom(src, 0, src.size());
src.close();
dest.close();
} catch (IOException e) {
e.printStackTrace();
}
}