title: Code not working on Phone, but working on Emulator, Why?
body: <p>This code works perfectly fine on an Emulator (Geneymotion), but doesn't work in phone, or tablet:</p>
  
  <pre><code>     Document doc = new Document();
       try {
  
                   String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
   + "/invoices";
  
                   File dir = new File(path);
                   if(!dir.exists())
                       dir.mkdirs();
  
                   Log.d("PDFCreator", "PDF Path: " + path);
  
                   File delete = new File(dir, "invoice.pdf");
                   if (delete.exists())
                       delete.delete();
  
                   File file = new File(dir, "invoice.pdf");
  
   FileOutputStream fOut = new FileOutputStream(file);
  
               PdfWriter.getInstance(doc, fOut);
  
               //open the document
               doc.open();
               Paragraph name = new Paragraph("NAME");
               doc.add(name);
       } catch (DocumentException de) {
                   Log.e("PDFCreator", "DocumentException:" + de);
               } catch (IOException e) {
                   Log.e("PDFCreator", "ioException:" + e);
               }
       finally
       {
          doc.close();
       }
  </code></pre>
  
  <p>I've added the required permissions.</p>
  
  <p>My question is, why would a piece of code work in an emulator, but not on the actual device? Isn't an emulator suppose to emulate a device? So shouldn't the outcome be the same?</p>
  
  <p>The above code runs when I click a button, in the emulator when I click that button, it creates the file in the designated directory, but when I test it in a phone, when I press the button, nothing happens, no file is created, nor is any folder created.</p>
  
  <p>What is the problem? Can anyone give me some direction please.</p>