电子邮件作曲家在android系统 [英] Email Composer in android

查看:104
本文介绍了电子邮件作曲家在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我想发送电子邮件给一个account.in点击一个按钮event.i用下面的code。这有例外

 公共无效的onClick(视图v){
             sendEmail(背景下,新的String [] {jayampalaniraja@gmail.com},发送电子邮件,测试电子邮件,我的身体);
        }        私人无效sendEmail(上下文的背景下,字符串[] recipientList,
                主题字符串,字符串的身体,字符串名称){
            意图emailIntent =新意图(android.content.Intent.ACTION_SEND);
            emailIntent.setType(纯/文);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,recipientList);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,学科);
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,体);
            emailIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);            尝试
            {
            context.startActivity(Intent.createChooser(emailIntent,标题));            }赶上(例外五)
            {
                的System.out.println(E);
            }
        }

例外,我越来越为

 03-19 19:13:19.553:我/的System.out(2010):android.util.AndroidRuntimeException:从活动上下文之外调用startActivity()需要FLAG_ACTIVITY_NEW_TASK旗。


解决方案

它的正常工作。首先要配置一个电子邮件客户端模拟器。在此输入code

 公共无效的onClick(视图v){            // TODO自动生成方法存根            意图emailIntent =新意图(android.content.Intent.ACTION_SEND);            字符串aEmailList [] = {pal@Yahoo.co.in};
            //字符串aEmailCCList [] = {};
            //字符串aEmailBCCList [] = {};            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,aEmailList);
            //emailIntent.putExtra(android.content.Intent.EXTRA_CC,aEmailCCList);
            //emailIntent.putExtra(android.content.Intent.EXTRA_BCC,aEmailBCCList);            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,我的主题);            emailIntent.setType(信息/ RFC822);
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,我的消息体。);
               尝试
               {
            startActivity(emailIntent);
               }赶上(android.content.ActivityNotFoundException前){
                Toast.makeText(about.this,有没有安装的电子邮件客户端,Toast.LENGTH_SHORT).show();
            }
               赶上(例外五){的System.out.println(E);}
        }

In my application i want send a email to one account.in one button click event.i used the below code . this have exception

public void onClick(View v) {
             sendEmail(context, new String[]{"jayampalaniraja@gmail.com"}, "Sending Email", "Test Email", "I am body");
        }

        private void sendEmail(Context context, String[] recipientList,
                String subject, String body, String title) {
            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);
            emailIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

            try
            {
            context.startActivity(Intent.createChooser(emailIntent, title));

            }catch(Exception e)
            {
                System.out.println(e);
            }   
        }

The exception I am getting as

 "03-19 19:13:19.553: I/System.out(2010): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.

解决方案

It's working fine. first thing to configure a email client for your emulator.enter code here

public void onClick(View v) {

            // TODO Auto-generated method stub

            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

            String aEmailList[] = { "pal@Yahoo.co.in" };
            //String aEmailCCList[] = { ""};
            //String aEmailBCCList[] = { "" };

            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
            //emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
            //emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);

            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");

            emailIntent.setType("message/rfc822");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My message body.");
               try
               {
            startActivity(emailIntent);
               }catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(about.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }


               catch(Exception e){ System.out.println(e);}
        }

这篇关于电子邮件作曲家在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆