hsjbrk
hsjbrk

Reputation: 23

how to send email from input fields - my code debugging

i seem to have encountered a problem here.. i have the 2 edittext boxes and one button. when i click the button it gives me an option of what way to send the message, however it does not capture what my inputs are but gives out a weird message saying This is a [email protected]@47b8f0d9. Neither does it go to email and fill up the subject header.

this is my code.

package com.emailmetest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Activity1 extends Activity implements OnClickListener {
    Button sendemail;
    TextView input1, input2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        sendemail =(Button)findViewById(R.id.sendemail);
        input1 = (TextView)findViewById(R.id.input1);
        input2 = (TextView)findViewById(R.id.input2);
        sendemail.setOnClickListener(this);
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT   , "\nThis is a Test" + input1 + input2);
        try {
            startActivity(Intent.createChooser(i, "Send via..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(this.getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }
    }
}

Upvotes: 1

Views: 303

Answers (1)

John Boker
John Boker

Reputation: 83719

try:

i.putExtra(Intent.EXTRA_TEXT   , "\nThis is a Test" + input1.getText().toString() + input2.getText().toString());

Upvotes: 1

Related Questions