android,发送电子邮件,小部件
android, send e-mail, widget
如何使用android中的小部件发送电子邮件?在我的 onUpdate()
方法中,我写了以下内容:
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);
其他操作,如打开新的 activity 或浏览器,可以正常工作,但这个不行。我做错了什么?
我想通了。代码没有错误,但显然,电子邮件应用程序应该 运行 以不同的方式。我在很多帖子中注意到它被称为 startActivity(Intent.createChooser(intentname,"OptionalTitle"))
。而且,顺便说一句,不需要 ACTION_SENDTO
,它现在可以与 ACTION_SEND
一起使用。
然后我将代码更改为:
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);
如何使用android中的小部件发送电子邮件?在我的 onUpdate()
方法中,我写了以下内容:
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);
其他操作,如打开新的 activity 或浏览器,可以正常工作,但这个不行。我做错了什么?
我想通了。代码没有错误,但显然,电子邮件应用程序应该 运行 以不同的方式。我在很多帖子中注意到它被称为 startActivity(Intent.createChooser(intentname,"OptionalTitle"))
。而且,顺便说一句,不需要 ACTION_SENDTO
,它现在可以与 ACTION_SEND
一起使用。
然后我将代码更改为:
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);