0
我需要发送一些数据作为电子邮件按钮click.I成功添加数据从编辑text.But我不知道如何发送数据从我的数据库中的数组。代码我需要发送PN [I] .I附加值的值等this.but它在这一行Android-如何发送字符串数组作为电子邮件正文
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"name:"+edt1.getText().toString()+"\n"+"products:"+pn[i]);
代码引起错误:
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mydb=buy_ltr.this.openOrCreateDatabase("addcart", MODE_PRIVATE, null);
Cursor cr = mydb.rawQuery("SELECT * FROM add2cart WHERE usr='"+cont+"'", null);
String [] pn = new String[cr.getCount()];
int i = 0;
while(cr.moveToNext())
{
String prp = cr.getString(cr.getColumnIndex("prate"));
pn[i] = prp;
i++;
}
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[]{"[email protected]", "",};
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"name:"+edt1.getText().toString()+"\n"+"address:"+edt2.getText().toString()+"\n"+"products:"+pn[i]);
emailIntent.setType("text/plain");
// emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
}
});
你想发送数组的所有条目还是仅发送特定条目? – 2015-01-21 11:35:42
我想发送数组的所有条目。 – paypaluser 2015-01-21 11:40:36
好吧,所以你将不得不将所有数组项合并成一个字符串。你想在项目之间分隔吗?也许是空格字符或逗号? – 2015-01-21 11:46:08