I have a problem with setting type "message/rfc822" for intent to send e-mail with file attachment on Android emulator. I have to use setType("message/rfc822") because file doesn't have standart MIME-type (sqlite database) and I am trying to avoid a lot of applications in select list for user's choice. For all API Levels before 2.3.3 I have an error:
java.lang.RuntimeException:
Unable to start activity ComponentInfo{my.cashwatcher/my.cashwatcher.SendEmailActivity}:
android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.SEND typ=message/rfc822
(has extras) }
In the case of API Level 2.3.3 code works fine and error doesn't appear. Is it a problem of Android emulator or old APIs!?
Code:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{appPrefs.getEmail("email")});
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), DATABASE_PATH)));
sendIntent.putExtra(Intent.EXTRA_TEXT, "body_of_email");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "APPLICATION_NAME");
startActivityForResult(sendIntent, EMAIL_SEND_RESULT);
First, "to avoid a lot of applications in select list for user's choice", use
ACTION_SENDTO
and amailto:
Uri
.Second, what you are experiencing is not "a problem of Android emulator" nor "old APIs". You need 1+ applications that are capable of handling the
ACTION_SEND
Intent
and a MIME type ofmessage/rfc822
. There is no guarantee that any given device will support that combination, let alone any given emulator. Your code needs to handle that, just as if you useACTION_GOBBLEDYGOOK
or a MIME type ofthisis/sonotreal
or whatever.Uri data = Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" + "blah blah body" + "&to=" + "sendme@me.com");
testIntent.setData(data);
startActivity(testIntent);
i have made an application which uses uri example as u desried: my function has on click listener activated :
}