在將其發送到 gmail 或其他電子郵件客戶端之前,我正在努力附加多個影像。我想讓每個按鈕都附加一個影像,例如我希望用戶在第一個按鈕上附加一個 ID 副本,然后是另一個按鈕,付款證明副本(影像)。
我的java代碼
private void openFolder() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
}
private void openFolder2() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_FROM_GALLERY && resultCode == RESULT_OK)
{
URI = data.getData();
tvAttachment.setText(URI.getLastPathSegment());
tvAttachment.setVisibility(View.INVISIBLE);
URI2 = data.getData();
tvAttachment2.setText(URI.getLastPathSegment());
tvAttachment2.setVisibility(View.INVISIBLE);
}
}
private void sendEmail() {
try {
String recipient = "[email protected]";
subject = etSubject.getText().toString();
message = "Full Name: " Name.getText().toString() "\n" "Cellphone No: " Number.getText().toString();
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
if (URI != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
}
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
this.startActivity(Intent.createChooser(emailIntent, "Sending email..."));
} catch (Throwable t) {
Toast.makeText(this, "Request failed, retry! " t.toString(), Toast.LENGTH_LONG).show();
}
}
uj5u.com熱心網友回復:
將您的sendEmail功能更改為以下內容:
private void sendEmail() {
try {
String recipient = "[email protected]";
subject = etSubject.getText().toString();
message = "Full Name: " Name.getText().toString() "\n" "Cellphone No: " Number.getText().toString();
final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("*/*");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(URI);
uris.add(URI2);
emailIntent.putExtra(Intent.EXTRA_STREAM, uris);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
this.startActivity(Intent.createChooser(emailIntent, "Sending email..."));
} catch (Throwable t) {
Toast.makeText(this, "Request failed, retry! " t.toString(), Toast.LENGTH_LONG).show();
}
}
正如評論中的某人指出的那樣,您的 MIME 型別無效(反轉)。最安全的選擇是使用"*/*". 您還需要ACTION_SEND_MULTIPLE用于 Intent 操作,因為您要附加多個 Uris。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/447491.html
