2014-04-22 116 views

回答

2

發現:

procedure TfrmSendMail.CreateEmail(const Recipient, Subject, Content, 
    Attachment, Attachment2: string); 
var 
    Intent: JIntent; 
    Uri: Jnet_Uri; 
    AttachmentFile: JFile; 

begin 
    Intent := TJIntent.Create; 
    Intent.setAction(TJIntent.JavaClass.ACTION_SEND_MULTIPLE); 
    Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); 
    Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, StringToJString(Recipient)); 
    Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(Subject)); 
    Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(Content)); 

    AttachmentFile := SharedActivity.getExternalFilesDir 
    (StringToJString(Attachment)); 


    Uri := TJnet_Uri.JavaClass.fromFile(AttachmentFile); 


    Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, 
    TJParcelable.Wrap((Uri as ILocalObject).GetObjectID)); 


    Intent.setType(StringToJString('vnd.android.cursor.dir/email')); 

    SharedActivity.startActivity(Intent); 
end; 
+0

此代碼濫用'Activity.getExternalFilesDir()'方法。假設'Attachment'是要附加的實際文件的完整路徑,請改用'AttachmentFile:= TJFile.JavaClass.init(StringToJString(Attachment))'。 –

+0

此外,'Intent.EXTRA_EMAIL'是[文檔](http://developer.android.com/reference/android/content/Intent.html#EXTRA_EMAIL)預期**數組**的字符串值,但你是而是傳遞一個**單**字符串。 –

相關問題