The file is generating fine. I decided to add some logic to handle if the device didn't have an external storage, or if the external storage was set to read-only; in which case, I would try to save the file to a specific directory in my app's filesystem. This works fine, too. The problem is when trying to get the third party app to show the file. I understand that I should be saving the file as Mode_World_Readable, but just can't get it to work from the examples I have found.
Here is an excerpt of my code:
//Build a filename from the data provided
String reportTitle = args.getFromDate() + "_" + args.getToDate() + ".pdf";
: : : :
: : : :
} else {
//Something else is wrong.
//Maybe there isn't a SD Card
//It may be one of many other states, but all we need
//to know is we can neither read nor write to external storage
mExternalStorageAvailable = mExternalStorageWriteable = false;
try {
//Get the absolute path to the filesystem directory
//where the internal files are saved.
File painReportFolder = ctx.getFilesDir();
//The string of the sub directory we want to access
String filename = "Reports/PainReports/";
//Create a new 'file' to build the directory
File file = new File(painReportFolder, filename);
//Make the directory if it doesn't exist
file.mkdirs();
//Build a FileOutputStream with the filename appended
theFile = new FileOutputStream(file + java.io.File.separator + reportTitle);
//This is what the examples suggest,
//But it doesn't work.
//In this configuration, at least
//FileOutputStream fos = openFileOutput(filename, Context.MODE_WORLD_READABLE);
: : : :
: : : :
// creation of the different writers
PdfWriter writer;
if(mExternalStorageAvailable == false && mExternalStorageWriteable == false){
//if no sd card, or sd card is read-only,
//write to specific directory in internal
writer = PdfWriter.getInstance(document, theFile );
}else{
//otherwise, write to a dir on the sd card
writer = PdfWriter.getInstance(document, new FileOutputStream(currentDirectory + java.io.File.separator + reportTitle));
}
So PdfWriter.getInstance() will accept a FileOutputStream, but it wont accept the FileOutputStream created by openFileOutput and I can't add MODE_WORLD_READABLE to 'theFile'
I've been researching this for the past week, and trying out different variations of code. Nothing I've found on Stackoverflow or anywhere else directly answers my query.