我必须开发一个 android 应用程序。在这里,我必须从我的 android 应用程序发送邮件。
我必须从我的 android 应用程序发送邮件 listview vlaues。
这是我的安卓代码:
public class InvoiceOrder extends Activity {
String mGrandTotal,mTitle,total,mCost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
ListView mLstView1 = (ListView) findViewById(R.id.listView1);
CustomerAdapter mViewCartAdpt = new CustomerAdapter(
InvoiceOrder.this);
mLstView1.setAdapter(mViewCartAdpt);
Button login = (Button) findViewById(R.id.mBtnSubmit);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"demo@mercuryminds.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Testing");
i.putExtra(Intent.EXTRA_TEXT , "mLstView1");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(InvoiceOrder.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
});
}
列表视图显示在这些活动中。我如何将该列表视图值发送到电子邮件。请给我解决方案。
编辑:
嗨,我已经自动发送邮件了。所以我使用了 javamailapi。
现在我改变了我的代码,如:
public class InvoiceOrder extends Activity {
String mGrandTotal,mTitle,total,mCost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
ListView mLstView1 = (ListView) findViewById(R.id.listView1);
CustomerAdapter mViewCartAdpt = new CustomerAdapter(
InvoiceOrder.this);
mLstView1.setAdapter(mViewCartAdpt);
Button login = (Button) findViewById(R.id.mBtnSubmit);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("mroslinmhary@gmail.com","fg565jhjjh");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("krishnaveni.veeman@mercuryminds.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("demo@mercuryminds.com"));
message.setSubject("Testing Subject");
message.setContent("This is your product name : "+
"Hi Krishna" +"<br></br>This is your price : "+ "Hi veni", "text/html; charset=utf-8");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
});
现在我必须自动将列表视图发送到电子邮件。我如何在此处设置内容。请给我想法。