So the files that I'm creating are working fine and showing up exactly how they should on an emulator, I just can't get them to export anywhere where I can see them on my actual device. These files need to be accessible outside the application but I can't seem to make that happen.
This is how I declare the file variable
File FeedingReport = new File(Environment.DIRECTORY_ALARMS, "Feeding_" + DateFormat.format(date) + ".csv");
And then writing
FeedingReport.createNewFile();
FileOutputStream writer = openFileOutput(FeedingReport.getName(), MODE_WORLD_READABLE);
Like I said, the writing works fine as everything works perfectly on an emulator. I've set my permissions to read & write internal and external storage and as you can see I'm trying loads of different directories that I can see on my actual phone (eg. ALARMS) but the file still isn't showing up there.
Whatever I try nothing seems to let me view this file, please help!
Try to inform the system about new files and directories which are created by you:
MediaScannerConnection.scanFile(MainActivity.this, new String[] {filePathWrite.toString()}, null, null);
//filePathWrite is Environment.DIRECTORY_ALARMS,
//"Feeding_" + DateFormat.format(date) + ".csv" in your case
I had the same problem but answer in here solved my problem.
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.