2017-04-04 25 views
-1

私は内部ストレージを使用していてもエラーは表示されませんが、作成されたファイルを見ることができません。私のマニフェストファイルで許可を与えても、許可が拒否されました。 私は、データベースからデータをフェッチするファイルを書き込むためにアクティビティから呼び出すクラスを作成しています。 ここにコードがあります。androidにファイルを書き込むことができません

 public boolean createPdfFile(String path, Employee employee,String month,Context context){ 
    boolean status=false; 
    if(path!=null && employee!=null){ 
     Document document=new Document(); 
     try{ 
      if(!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){ 
       Toast.makeText(this, "External SD card not mounted", Toast.LENGTH_LONG).show(); 
      } 
      File sdCard=Environment.getExternalStorageDirectory(); 
      File file=new File(sdCard,month+"_"+employee.getEmployeeName()+".pdf"); 
      PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream(file)); 
      writer.setEncryption(employee.getDateOfBirth().getBytes(),employee.getEmployeeName().getBytes(), PdfWriter.ALLOW_PRINTING,PdfWriter.ENCRYPTION_AES_128); 
      document.open(); 
      Paragraph p=new Paragraph(); 
      p.add("Payslip for the month of January"); 
      p.setFont(new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(1, 1, 1))); 
      p.setAlignment(Element.ALIGN_CENTER); 
      document.add(p); 
      PdfPTable table=new PdfPTable(2); 
      table.setWidthPercentage(100); //Width 100% 
      table.setSpacingBefore(10f); //Space before table 
      table.setSpacingAfter(10f); //Space after table 
      float[] columnWidths = {1.5f, 1.5f}; 
      table.setWidths(columnWidths); 
      table.addCell("Employee Code"); 
      table.addCell(employee.getEmployeeID()); 
      table.addCell("Department"); 
      table.addCell(employee.getDepartment().getDepartmentName()); 
      table.addCell("Date of Birth"); 
      table.addCell(employee.getDateOfBirth()); 
      table.addCell("Date of Joining"); 
      table.addCell(employee.getDateOfJoining()); 
      table.addCell("Employee Name"); 
      table.addCell(employee.getEmployeeName()); 
      document.add(table); 
      document.close(); 
      writer.close(); 
      status=true; 
     }catch (FileNotFoundException e) { 
      status=false; 
      Log.e("PDF exception aaa",e.getMessage()); 
     }catch (DocumentException e) { 
      status=false; 
      Log.e("PDF exception abc",e.getMessage()); 
     } catch (IOException e) { 
      status=false; 
      Log.e("PDF exception",e.getMessage()); 
     } 
    } 
    return status; 
} 
+0

http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it [Androidの許可の –

+0

可能な重複は」doesnの私がそれを宣言したとしても仕事はしない](http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it) – Emad

答えて

関連する問題