How to send e-mail using widget in android? In my onUpdate()
method I've written the following:
Intent intent3 = new Intent(Intent.ACTION_SEND);
intent3.setData(Uri.parse("mailto:"));
intent3.setType("text/plain");
intent3.putExtra(Intent.EXTRA_EMAIL, new String[]{"abc@gmail.com"});
intent3.putExtra(Intent.EXTRA_SUBJECT,"Temat");
intent3.putExtra(Intent.EXTRA_TEXT, "Tekst wiadomości");
PendingIntent pendingEmailIntent = PendingIntent.getActivity(context,0,intent3,0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
remoteViews.setOnClickPendingIntent(R.id.email_button,pendingEmailIntent);
Other actions, like opening new activity or a browser, work as suspected, but this one not. What am I doing wrong?
I figured this out. There was no errors in code, but apparently, the e-mail app should be run in a different way. I've noticed in many posts that it is called like startActivity(Intent.createChooser(intentname,"OptionalTitle"))
. And, by the way, there's no need for ACTION_SENDTO
, it works with ACTION_SEND
now.
Then I've changed my code to:
Intent intent3 = new Intent(Intent.ACTION_SEND);
intent3.setData(Uri.parse("mailto:"));
intent3.setType("text/plain");
intent3.putExtra(Intent.EXTRA_EMAIL, new String[]{"abc@gmail.com"});
intent3.putExtra(Intent.EXTRA_SUBJECT,"Temat");
intent3.putExtra(Intent.EXTRA_TEXT, "Tekst wiadomości");
PendingIntent pendingEmailIntent = PendingIntent.getActivity(context,0,Intent.createChooser(intent3,"Choose"),0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
remoteViews.setOnClickPendingIntent(R.id.email_button,pendingEmailIntent);
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.