我正在使用我的應用程序中的反饋功能,用戶應該從圖庫中選擇圖像並鍵入他的消息並按發送按鈕,發送按鈕時單擊代碼應該是從框中獲得文本(下圖),並將其附加到電子郵件意圖併發送整個事情,一切似乎工作得很好,直到我得到「無法附上空文件」吐司消息,這是我多遠得到了在代碼Android - 將圖像附加到電子郵件
String rating = String.valueOf(RateBar.getRating());
String subject = Feedback.getText().toString();
String FileLocation = FilePathPreview.getText().toString();
String to ="[email protected]";
String message = UserInput.getText().toString();
String body = "Rating : "+rating+" out of 5"+
"\n "+message;
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, body);
email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+FileLocation));
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
public void grabImg(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String PathP = selectedImage.getPath().toString();
FilePathPreview.setText(PathP);
}
}
我想預先等待'file:/'是什麼破壞你的代碼。嘗試擺脫這一點。 – theFunkyEngineer
'String PathP = selectedImage.getPath()。toString();'是無用的,除非'Uri'的方案可能是'file'。另外,請記住,ACTION_SEND支持* EXTRA_TEXT *或EXTRA_STREAM *,但不一定是兩者。 – CommonsWare
'String FileLocation = FilePathPreview.getText()。toString();'你沒有告訴它什麼。你當然應該。 – greenapps