Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:17:42+00:00 2026-06-12T13:17:42+00:00

The file is generating fine. I decided to add some logic to handle if

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:17:43+00:00Added an answer on June 12, 2026 at 1:17 pm

    Don’t know why this was downvoted, or by whom (probably some troll, as no comment was left), but further research has shown to me that there is no solution.

    Why?

    Take out your sd card and try to take a photo; it says that it needs a card – it wont save to internal; and this is a bundled app.

    So I’ve rolled-back all of my sd checking code:

    If there is sd; save

    If there is sd, but it is read-only; show error page

    If there is no sd; show error page

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XSLT file generating plain HTML. I need to wrap some elements
i am generating *.reg file using code which will have some important data. and
i am generating CSV,the file is generated very fine but i have problem in
I have developed a web project. Which is generating log file using log4j. But
I am generating an Excel file through MATLAB and I have empty cells in
I have a app that uses Prawn to do some PDF generating, it works
I'm generating some CSV output using Ruby's built-in CSV. Everything works fine, but the
I have a large nested array that I'm generating from parsing a CSV file
I am generating the barcode generation of barcode is working fine barcode also read
I'm dynamically generating a layout, and to do this I have a menu_row_element.xml file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.