任何人都可以幫助解釋爲什麼此代碼在Geneymotion模擬器中工作,但不在任何實際的Android設備中?代碼在模擬器中完美工作,我對它沒有任何問題,我完全不知道爲什麼它在實際設備中不起作用。AndroidStudio將PDF附加到電子郵件問題
這裏的方法,該方法被調用時,點擊「創建PDF」按鈕:
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();
Log.d("test", "PDF Doccument Opened for input");
在模擬器: - 當我點擊「創建PDF」按鈕,郵件意圖被調用,我可以選擇使用電子郵件客戶端並通過它發送PDF。
在實際的Android設備中: 當我在實際設備中單擊「創建PDF」時,絕對沒有任何反應。
我認爲問題可能圍繞我要存儲PDF的目錄進行,但我無法解決它。
如果有人能幫助我,將不勝感激。提前致謝。
注意:我使用DroidText庫來生成PDF。從實際設備上測試
日誌說:
11-05 21:09:14.839 10375-10375/motawaze.com.invoicepdf D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 93K, 47% free 2913K/5447K, external 0K/0K, paused 30ms
11-05 21:09:25.989 10375-10375/motawaze.com.invoicepdf D/CLIPBOARD﹕ Hide Clipboard dialog at Starting input: finished by someone else... !
11-05 21:09:29.849 10375-10378/motawaze.com.invoicepdf D/dalvikvm﹕ GC_CONCURRENT freed 153K, 47% free 3043K/5639K, external 171K/1281K, paused 7ms+2ms
11-05 21:09:39.899 10375-10378/motawaze.com.invoicepdf D/dalvikvm﹕ GC_CONCURRENT freed 351K, 48% free 3105K/5895K, external 171K/1281K, paused 7ms+3ms
11-05 21:09:53.639 10375-10375/motawaze.com.invoicepdf D/test﹕ set the fields for PDF input
11-05 21:09:53.649 10375-10375/motawaze.com.invoicepdf D/test﹕ set the document
11-05 21:09:53.669 10375-10375/motawaze.com.invoicepdf D/test﹕ set the calender
11-05 21:09:53.669 10375-10375/motawaze.com.invoicepdf D/PDFCreator﹕ PDF Path: /mnt/sdcard/Download/invoices
11-05 21:09:53.669 10375-10375/motawaze.com.invoicepdf E/PDFCreator﹕ ioException:java.io.FileNotFoundException: /mnt/sdcard/Download/invoices/Invoice.pdf (No such file or directory)
11-05 21:10:31.420 10375-10378/motawaze.com.invoicepdf D/dalvikvm﹕ GC_CONCURRENT freed 358K, 48% free 3152K/5959K, external 171K/1281K, paused 7ms+2ms
請在這裏發表您的日誌。 –
如果代碼在模擬器中沒有問題,我看不到如何發佈日誌? –
我只想看看你在這一行中得到了什麼:Log.d(「PDFCreator」,「PDF Path:」+ path); –