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 clic开发者_JAVA百科k 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 Testandroid.widget.EditText@47b84299android.widget.EditText@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[]{"test@hotmail.com"});
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();
}
}
}
try:
i.putExtra(Intent.EXTRA_TEXT , "\nThis is a Test" + input1.getText().toString() + input2.getText().toString());
精彩评论