我來自stackoverflow的新用戶。我的Android應用程序出現了一些小問題,特別是使用ImageView觸發事件。此事件打開一個預先寫好文本的電子郵件客戶端,它應該附加圖像的圖像。我已經知道圖像應該轉換成位圖之前,然後壓縮併發送到電子郵件客戶端,但不幸的是我不是一個Android/Java專家,所以我無法找到如何做到這一點。這是電子郵件方法的代碼:Android:發送電子郵件,圖像來自ImageView
新的代碼下面
哪裏我不得不更換「字符串imageURI = NULL;」與電子郵件需要的形象。謝謝你們!
編輯:
我設法修改我的代碼,這個,那個沒有給出錯誤:
public void sendMail(ImageView image){
Intent i = new Intent(Intent.ACTION_SEND);
int imageURI = R.drawable.img1;
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
i.putExtra(Intent.EXTRA_TEXT , "Globelife");
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+getPackageName()+"/"+imageURI));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Test01Activity.this, "Non sono presenti app per l'invio di e-mails.", Toast.LENGTH_SHORT).show();
}
}
但我需要改變 「INT imageURI = R.drawable.img1;」到「int imageURI = ImageView.src;」或類似的東西
要發送的圖像保存在本地SD卡上,還是來自Internet? – 2012-07-11 08:30:16
圖像是在應用程序的可繪製文件夾中 – Stefano 2012-07-11 09:22:28