【发布时间】:2017-10-28 14:41:29
【问题描述】:
以下是用于发送电子邮件的 java 和 xml 文件。请验证代码。我已经注册了按钮,但它仍然不起作用。
错误:无法在表面 0xe2d19220 上设置 EGL_SWAP_BEHAVIOR, 错误=EGL_SUCCESS.跳过 37 帧! 应用程序可能在其主线程上做了太多工作
MainActivity.java
public void onClick(View view) {
Intent intent = null,
intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("mailto:"));
String[] to = {"honeysonwani88@gmail.com", ""};
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_SUBJECT, "subject to your app");
intent.putExtra(Intent.EXTRA_TEXT, "text inside email");
intent.setType("message/rfc822");
chooser = Intent.createChooser(intent, "Send email");
startActivity(chooser);
}
activity_main.xml
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Email"
/>
【问题讨论】:
-
请“详细”解释“不起作用”是什么意思。请注意
ACTION_SENDTOis not documented to support any of those extras,而Uri应该用来识别收件人。 -
点击一个按钮,什么都没有发生。我在这里做错了什么?
-
也许您没有将此
onClick()方法连接到按钮。要么它应该启动一个活动,要么你应该以ActivityNotFoundException崩溃。 -
成功了。这是不正确的按钮 ID。谢谢@CommonsWare
标签: java android xml android-implicit-intent