【问题标题】:How do I mail TextView data on button click in Android app?如何在 Android 应用程序中单击按钮时发送 TextView 数据?
【发布时间】:2014-05-01 13:04:51
【问题描述】:

首先,我对 Android 和 NFC 都很陌生,尽管我对 Java 很熟悉。我正在制作一个 NFC android 应用程序作为我的主要项目,我想邮寄某个列表(显示结果)单击按钮

谁能帮我写代码或指导我看一些分步教程...

谢谢期待..!!!

【问题讨论】:

    标签: java android button jakarta-mail


    【解决方案1】:

    使用Intent 启动能够发送邮件并传递您的数据的应用程序:

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                "mailto","abc@gmail.com", null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT");
    startActivity(Intent.createChooser(emailIntent, "Send email..."));
    

    【讨论】:

    • @DroidBender 选择器是否自动显示相关应用程序..??以及如何将 TextView 数据作为电子邮件文本传递..??
    【解决方案2】:
    In above code just add this line:
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Content of the email");
    

    【讨论】:

    • @Imran 你能告诉我如何修改此代码以从另一个活动中获取文本正文和主题...并告诉我是否需要对清单进行一些修改。
    【解决方案3】:
    if you want to get body of email from another activity then pass edittext text in intent from activity where your edittext is and receive it to another activity where your intent is
    
    for example
    Activity A
    
    EditText bodyText=(EditText)findViewById(R.id.body_text);
    EditText subjectText=(EditText)findViewById(R.id.subject_text);
    
    String emailBody=bodyText.getText().toString().trim();
    String emailSubject=subjectText.getText().toString().trim();
    
    Intent inte=new Intent(A.this,B.class);
    inte.putExtra("body",bodyText);
    inte.purExtra("subject",emailSubject);
    startActivity(inte);
    
    and in Activity B receive the intent like this,
    
    Intent intent=getIntent();
    String bodyText=intent.getExtras().getString("body");
    String subjectText=intent.getExtras().getString("subject");
    
    Intent emailInte=new Intent(Intent.ACTION_SENDTO,Uri.fromParts("mailto","xyz@gmail.com",null));
    emailInte.putExtra(Intent.EXTRA_SUBJECT,subjectText);
    emailInte.putExtra(Intent.EXTRA_TEXT, bodyText);
    startActivity(Intent.createChooser(emailInte,"Send email using"));
    

    【讨论】:

    • 我已经使用 Android Intent 对我的代码进行了一些更改,现在我遇到了一个致命错误。我发布了一个带有代码和 LogCat 问题日志的新问题。请参考并帮助我:New Question Here
    猜你喜欢
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多