【发布时间】:2018-03-05 23:34:51
【问题描述】:
我正在尝试简单地发送一封电子邮件,其中包含我数据库中的数据作为电子邮件中的文本。
我搜索了大量帖子,不想作为附件发送,我不想保存到外部存储等,找不到我要找的东西。
我希望填充数据库中的所有行,但只能设法获取一行。任何帮助将不胜感激。
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String[] projection = {
LogEntry._ID,
LogEntry.COLUMN_LOG_DATE,
LogEntry.COLUMN_LOG_DESTINATION,
LogEntry.COLUMN_LOG_PURPOSE,
LogEntry.COLUMN_LOG_MILEAGE};
Cursor cursor = getContentResolver().query(
LogEntry.CONTENT_URI,
projection,
null,
null,
null);
//TODO ???????????? I want the cursor to continue and get all the data from the database???
//This is the current result in the email.
// 1
// 05 Mar 2018
// 12:10:52 PM
// 0
// 0
// 88031
// Extract the properties from cursor
// Find columns of log attributes that I am interested in
int idColumnIndex = cursor.getColumnIndex(LogEntry._ID);
int dateColumnIndex = cursor.getColumnIndex(LogEntry.COLUMN_LOG_DATE);
int destinationColumnIndex = cursor.getColumnIndex(LogEntry.COLUMN_LOG_DESTINATION);
int purposeColumnIndex = cursor.getColumnIndex(LogEntry.COLUMN_LOG_PURPOSE);
int mileageColumnIndex = cursor.getColumnIndex(LogEntry.COLUMN_LOG_MILEAGE);
String id = cursor.getString(idColumnIndex);
String date = cursor.getString(dateColumnIndex);
int destination = cursor.getInt(destinationColumnIndex);
int purpose = cursor.getInt(purposeColumnIndex);
String mileage = cursor.getString(mileageColumnIndex);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"recipent@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "All Logs for " + LogEntry.COLUMN_LOG_DATE);
emailIntent.putExtra(Intent.EXTRA_TEXT, id + "\n" + date + "\n" + destination + "\n" + purpose + "\n" + mileage);
startActivity(Intent.createChooser(emailIntent, "Select App"));
【问题讨论】:
-
您将遍历
Cursor以获取其所有行,并使用StringBuilder构建整个文本。请参阅moveToNext()等方法。 -
@CommonsWare 感谢您的快速回复。所以我调查了这个并使用了这个链接stackoverflow.com/a/12728360。我还在搞砸它,试图让它工作。
标签: java android sqlite android-intent cursor