Android 中的意图类型 ACTION_SENDTO。它是如何运作的?
在我的应用程序中,我想向某人(电话中的联系人)发送消息,并且我希望用户决定他将使用哪个渠道(短信、电子邮件……)。
文档建议在这种情况下应使用 ACTION_SENDTO。我使用以下代码:
private static void launchNewShareIntent(Context c, String subject, String text, String dialogTitle, Uri recipient) {
Intent shareintent = new Intent(Intent.ACTION_SENDTO);
shareintent.setData(recipient);
shareintent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareintent.putExtra(Intent.EXTRA_TEXT, text);
shareintent.setType("text/plain");
shareintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(Intent.createChooser(shareintent, dialogTitle));
}
其中收件人例如: content://com.android.contacts/contacts/755
但是,手机会显示一个对话框:“没有应用程序可以执行此操作”。
有人成功使用 ACTION_SENDTO 吗?
In my application I would like to send a message to someone (contact in phone) and I want user to decide which channel (SMS, e-mail, ...) he will use.
Documentation suggest that ACTION_SENDTO shall be used in this case. I'm using following code:
private static void launchNewShareIntent(Context c, String subject, String text, String dialogTitle, Uri recipient) {
Intent shareintent = new Intent(Intent.ACTION_SENDTO);
shareintent.setData(recipient);
shareintent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareintent.putExtra(Intent.EXTRA_TEXT, text);
shareintent.setType("text/plain");
shareintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(Intent.createChooser(shareintent, dialogTitle));
}
where recipient is for example: content://com.android.contacts/contacts/755
However, the phone displays a dialog box with: "No applications can perform this action."
Has anybody succeeded with ACTION_SENDTO?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ACTION_SENDTO 似乎不支持像您正在使用的那样的联系人,我也没有在文档中看到任何暗示这一点的内容(至少对我来说)。然而,传递 URI(例如 sms://2065551212)对我来说效果很好。另请注意,ACTION_SENDTO 不支持 EXTRA_SUBJECT 或 EXTRA_TEXT。请参阅ACTION_SENDTO 发送电子邮件
谢谢,
——兰迪
ACTION_SENDTO does not appear to support a contact like you are using it, nor did I see anything in the documentation that implies that (to me, at least). Passing a URI such as sms://2065551212, however, worked great for me. Note, also, that ACTION_SENDTO does not support EXTRA_SUBJECT nor EXTRA_TEXT. See ACTION_SENDTO for sending an email
Thanks,
--randy