2014-10-31 78 views
0

有時我會看到沒有附件的電子郵件。發送附件始終不起作用

我懷疑這發生在文件大小比處理程序大的時候。

我發送碼 -

 Intent email = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 

     email.putExtra(Intent.EXTRA_SUBJECT, "Device Logs"); 

     email.setType("text/plain"); 

     email.putExtra(Intent.EXTRA_TEXT, getEmailContents()); 

     File file = writeLogFile(); 

     ArrayList<Uri> uriList = new ArrayList<Uri>(); 

     Uri uri = Uri.fromFile(file); 

     uriList.add(uri); 

     email.putExtra(Intent.EXTRA_STREAM, uriList); 

     startActivity(Intent.createChooser(email, "Choose an Email client :")); 

文件代碼 -

public File writeLogFile() 
     { 

      if(builder != null) 
      { 
       for(int i =0;i <receiptlist.size();i++) 
       { 
        builder.append(receiptlist.get(i) + "\n"); 
       } 
      } 

      //to create a Text file name "logcat.txt" in SDCard 
      File sdCard = Environment.getExternalStorageDirectory(); 
      File dir = new File (sdCard.getAbsolutePath() + "/myLogcat"); 

      if(!dir.exists()) 
       dir.mkdirs(); 

      File file = new File(dir, "logcat.txt"); 

      try {  
        //to write logcat in text file 
        FileOutputStream fOut = new FileOutputStream(file); 
        OutputStreamWriter osw = new OutputStreamWriter(fOut); 

        // Write the string to the file 
        osw.write(builder.toString());    
        osw.flush(); 
        osw.close(); 
       } catch (FileNotFoundException e) { 
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 

       return file; 
     } 

我在做什麼錯?

回答

0

已解決問題 - 我在onDestroy()刪除了文件。

@Override 
    public void onDestroy() 
    { 
     super.onDestroy(); 
     File sdCard = Environment.getExternalStorageDirectory(); 
     String sdPath = sdCard.getAbsolutePath() + "/myLogcat"; 

     File sdDir = new File(sdPath); 

     if(sdDir.exists()) 
      deleteRecursive(sdDir); 
    } 

所以,如果用戶在活動和發送文件,那麼它被髮送,但如果用戶離開活動和回來,然後發送它不發送,因爲離開活動已刪除的文件。