0

I am trying to make a basic contact form app where people can fill in the needed information and press the send button and have the information sent to a specific E-mail. I have put it together but for some reason it is not working. The Java file has code in it from a similar app. The Java file has spinner code in it so I turned it into notes.. not sure if it's messing something up. Here is the code please let me know what I can do to make it work.

activity_main.xml:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <EditText
            android:id="@+id/etName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:ems="10"
            android:hint="Enter First and Last Name"
            android:inputType="textPersonName" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/etPhone"      
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/etName"
            android:layout_marginTop="14dp"
            android:ems="10"
            android:hint="Enter Phone #"
            android:inputType="phone" />

        <EditText
            android:id="@+id/etEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/etPhone"
            android:layout_marginTop="17dp"
            android:ems="10"
            android:hint="Enter E-mail"
            android:inputType="textEmailAddress" />

        <EditText
            android:id="@+id/etAdd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"       
            android:layout_below="@+id/etEmail"
            android:layout_marginTop="18dp"
            android:ems="10"
            android:hint="Enter Additional Information Here"
            android:lines="3"
            android:inputType="textMultiLine" />

        <Button
            android:id="@+id/send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/etAdd"
            android:text="Send" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/etPhone"
            android:layout_alignParentTop="true"
            android:gravity="center"
            android:text="Contact Form"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

Here is the MainActivity.java file:

package com.example.contactform1;

    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.os.Bundle;
    import android.text.Html;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Spinner;
    import android.widget.Toast;

    public class MainActivity  extends Activity implements OnClickListener, OnItemSelectedListener{
    /** Called when the activity is first created. */

        EditText etname, etphone, etemail, etadd;

        //Spinner subject;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    

        etname = (EditText) findViewById (R.id.etName);

        etphone = (EditText) findViewById(R.id.etPhone);
        etemail = (EditText) findViewById(R.id.etEmail);       
        etadd = (EditText)findViewById(R.id.etAdd);

        //subject=(Spinner)findViewById(R.id.spinner);
        //String subjects[]=new String[]{"Default","Klacht","Vraag","Opmerking","Applicatie"};
        //subject.setOnItemSelectedListener(this);
        //ArrayAdapter<String> sa = new ArrayAdapter<String>(getApplicationContext(),
            //android.R.layout.simple_spinner_item, subjects);
        //sa.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
        //subject.setAdapter(sa);;        


        final Button buttonSend= (Button)findViewById(R.id.send);        
        buttonSend.setOnClickListener(this);
      }

    public void onClick(View v) 
    {
             //if(etname.getText().toString().length()==0)  
             //{           
              //etname.setError( "Vul uw naam in" );  
             //}  
             //else if(etphone.getText().toString().length()==0)  
             //{           
              //etphone.setError( "Vul uw email in" ); 
             //}
             //else if(etemail.getText().toString().length() != 10)  
             //{           
              //etemail.setError( "Vul een geldig telefoonnummer in" );
             //}
             //else if(etadd.getText().toString().length()==0)  
             //{           
              //etadd.setError( "Vul uw bericht in" );  
             //}
             //else if(subject.getSelectedItemPosition()==0)  
             //{           
              //Toast.makeText(MainActivity.this,"Please select the Subject",Toast.LENGTH_SHORT).show(); 
             //}
             //else
             //{  
                //String body=
             //"Name : "+etname.getText().toString()+"<br>Mobile :"+etphone.getText().toString()+
              //"<br>Email :"+etemail.getText().toString();//+"<br>Bericht :"+etadd.getText().toString();  

                //Intent email = new Intent(Intent.ACTION_SEND); 
                //email.putExtra(Intent.EXTRA_EMAIL, new String[]{"email here"});           
                //email.putExtra(Intent.EXTRA_SUBJECT, subject.getSelectedItem().toString()); 
                //email.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body)); 
                //email.setType("message/rfc822");
                //startActivityForResult(Intent.createChooser(email, "marketing"),1); 
             }         
     // }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {

        new AlertDialog.Builder(MainActivity.this)
    .setMessage("Your requested has been Accepted\nThank You")
    .setCancelable(false)
    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) 
    {
      dialog.cancel();
        }
    })  
        .show();
    }

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }
    }

LogCat info:

12-04 18:19:15.574: W/IInputConnectionWrapper(28530): showStatusIcon on inactive InputConnection
12-04 18:19:21.190: D/AbsListView(28530): Get MotionRecognitionManager
12-04 18:19:21.220: D/AbsListView(28530): onVisibilityChanged() is called, visibility : 4
12-04 18:19:21.220: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:21.230: D/AbsListView(28530): onVisibilityChanged() is called, visibility : 0
12-04 18:19:21.230: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:21.240: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:21.320: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:21.330: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:21.360: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:21.390: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:22.591: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:22.861: W/IInputConnectionWrapper(28530): showStatusIcon on inactive InputConnection
12-04 18:19:22.982: D/AbsListView(28530): onDetachedFromWindow
12-04 18:19:22.982: D/AbsListView(28530): unregisterIRListener() is called 
12-04 18:19:37.546: E/ViewRootImpl(28530): sendUserActionEvent() mView == null
12-04 18:19:40.499: W/IInputConnectionWrapper(28530): showStatusIcon on inactive InputConnection
12-04 18:19:40.519: E/OpenGLRenderer(28530): SFEffectCache:clear(), mSize = 0

I have the form appearing now but the information that you input is not getting sent to the email. I am getting prompted to a screen indication which email service i should use to execute this app. I just want the information entered to be directly sent to the email that is provided in the app.

Thanks in advance!

OliverTwist
  • 43
  • 2
  • 8

1 Answers1

0

You're seeing that screen with the list of email clients because that's how Intents work.

An intent won't directly execute the action you want it to, all it can do is hand off the data to another Activity (perhaps in a different application) that can handle the data.

Victor KP
  • 437
  • 3
  • 10
  • Do you have any recommendations on how I could get all the contact information (starting another activity) sent to at least the content part of an email? – OliverTwist Dec 05 '13 at 03:25
  • What I want to accomplish is, once the send button is pressed, I want it to be sent directly to my gmail. That's it. No additional apps to accomplish the task – OliverTwist Dec 14 '13 at 14:14
  • Well then you will need to implement your own email client... You're trying to use Intents in a way that they were not designed for. – Victor KP Dec 14 '13 at 21:46