简体   繁体   中英

How to send mail only through email clients in my android application

How to send mail through only email clients from my android application.

I am using the below code in my application but its opeing messeges and bluetooth also. I need only Email clients like Gmail or yahoo .

  Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/rfc822");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "mailto@gmail.com");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");
    startActivity(Intent.createChooser(emailIntent, "Email:"))

Just Go on to Use this Code...It will always invoke your default Email Client.

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);

Is this of any help? This one is using the gmail client it seems.

Intent URI to launch Gmail App

I use this way to avoid choosing other app but default email client.

Intent it = new Intent(Intent.ACTION_SEND);
it.setType("text/plain");
it.putExtra(Intent.EXTRA_EMAIL, new String[]{emailAddr});
it.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
it.putExtra(Intent.EXTRA_TEXT, emailContent);
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + emailAddr));
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityInfo info = emailIntent.resolveActivityInfo(mContext.getPackageManager(), PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
    it.setPackage(info.packageName);
}

mContext.startActivity(it);

I hope it can help you ~

I made it work using this:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("mp3/3gp");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "recording voice");
Uri eri=Uri.parse(rlm.getPlayList().get(position).get("songPath"));
emailIntent.putExtra(Intent.EXTRA_STREAM,eri);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "hello, it is the recorded file of our conversassion");
emailIntent.putExtra(Intent.EXTRA_STREAM,rlm.getPlayList().get(position).get("songPath") );
RecordedList.this.startActivity(Intent.createChooser(emailIntent, "Send Email"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM