電子メールを起動してデータベースクエリからの情報を入力する方法を考え出しましたが、代わりにこれを CSV ファイルに書き込んで、Excel を使用してフォーマットできるようにしたいと思います (この場合、電子メールに添付される可能性があります)。全然可能です)。
以下は、電子メールに送信するテキストを作成する私のコードです。
private void exportRedRiskItemsToEmail(){
recipient = email;
subject.append(inspectionRef).append(" - Locators Rack Inspection Report (Red Risk Items)");
message.append("Dear ").append(contactFirstName).append(",\r\n");
message.append("\r\n");
message.append("Following todays inspection, below is a list of locations which are noted as Red Risk:\r\n");
final Cursor areasCursor = (Cursor) rmDbHelper.fetchAllAreasForInspection(inspectionId);
if(areasCursor.moveToFirst()){
do{
areaId = areasCursor.getLong(areasCursor.getColumnIndex(RMDbAdapter.AREA_ID));
areaNumber = RMUtilities.notEmpty(areasCursor.getString(areasCursor.getColumnIndex(RMDbAdapter.AREA_NUMBER)), "number unknown");
areaRef = RMUtilities.notEmpty(areasCursor.getString(areasCursor.getColumnIndex(RMDbAdapter.AREA_REF)), "");
if (areaRef != ""){
areaRef = " (" + areaRef + ")";
}
message.append("______________________________________________________").append("\r\n");
message.append("\r\n");
message.append("Area ").append(areaNumber).append(areaRef).append("\r\n");
message.append("\r\n");
}
while (areasCursor.moveToNext());
}
areasCursor.close();
message.append("______________________________________________________").append("\r\n");
message.append("\r\n");
message.append("Please fully off-load above locations (for uprights, please off-load bays either side). \r\n");
message.append("\r\n");
message.append("We will follow up with our full report and quotation for repairs shortly. \r\n");
message.append("\r\n");
message.append("In the meantime, if you have any queries, please give me a call on 07970 088845. \r\n");
message.append("\r\n");
message.append("Kind regards, \r\n");
message.append("\r\n");
message.append(inspector).append("\r\n");
sendEmail(recipient, subject.toString(), message.toString());
}
電子メールを起動するコードは次のとおりです。
private void sendEmail(String recipient, String subject, String message) {
try {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.setType("message/rfc822");
// emailIntent.setType("high/priority"); //This didn't work - any way to do this though!?
if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} catch (ActivityNotFoundException e) {
// cannot send email for some reason
}
}
どんなポインタでも大歓迎です。