如何让ImageButton在点击时直接打开电子邮件编辑器?

发布于 2024-11-16 07:19:36 字数 695 浏览 2 评论 0原文

我为电子纸/电子杂志制作了一个应用程序,其中我想为电子邮件编辑器提供一个图像按钮,如果我单击该按钮,它将直接打开电子邮件编辑器,将该页面的所有数据插入到电子邮件编辑器消息正文中,仅询问收件人地址。

我有输出,但它没有打开电子邮件,而是打开弹出列表,询问消息传递和蓝牙。

这是我的代码:

final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "App Error Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, "stacktrace");
activity(Intent.createChooser(emailIntent, "Send error report..."));

I have made one application for epaper/emagazine in which I want to give an imagebutton for email composer that if I click on that button it will directly open the email composer inserting all the data of that page to the email composer message body asking only recipient address.

I have the output but instead of email it opens popup list asking messaging and bluetooth.

This is my code:

final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "App Error Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, "stacktrace");
activity(Intent.createChooser(emailIntent, "Send error report..."));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜点 2024-11-23 07:19:36

单击按钮时调用 sendEmail() 方法:

final Context context = getApplicationContext();    
Button button = (Button) findViewById(R.id.openpdfbutton);          
button.setOnClickListener(new OnClickListener() {               
    public void onClick(View arg0) {
        sendEmail(context, new String[]{"[email protected]"}, "Sending Email",
                  "Test Email", "I am body");
    }
});

定义 sendEmail() 方法:

public static void sendEmail(Context context, String[] recipientList,
            String title, String subject, String body) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);    
    emailIntent.setType("plain/text");    
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);   
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    context.startActivity(Intent.createChooser(emailIntent, title));
}

并在 AndroidManifest.xml 文件中设置权限:

<uses-permission android:name="android.permission.INTERNET" />

Call sendEmail() method on button click:

final Context context = getApplicationContext();    
Button button = (Button) findViewById(R.id.openpdfbutton);          
button.setOnClickListener(new OnClickListener() {               
    public void onClick(View arg0) {
        sendEmail(context, new String[]{"[email protected]"}, "Sending Email",
                  "Test Email", "I am body");
    }
});

Define the sendEmail() method:

public static void sendEmail(Context context, String[] recipientList,
            String title, String subject, String body) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);    
    emailIntent.setType("plain/text");    
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);   
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    context.startActivity(Intent.createChooser(emailIntent, title));
}

And set permission in AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
感性 2024-11-23 07:19:36
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

使用意图我们不需要许可..

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

using intent we don't need permission..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文