0

I am doing a android application. I want the inputs in the contact form to be received in my personal mail account. I have tried several other codes. But the issue is when I hit the submit button, the mail interface will pop up. I do not want this. I want exactly how we see in the website, where we fill all the details in the contact form and the details have to be received in the personal mail or the company mail. Please help. The code is as follows.

<TextView
    android:id="@+id/contacttext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="8dp"
    android:textSize="20sp"
    android:textStyle="bold"
    android:gravity="center_horizontal"
    android:text="@string/contacttext" />

<EditText
    android:id="@+id/edit_name"
    android:layout_width="290dp"
    android:layout_height="40dp"
    android:layout_below="@id/contacttext"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="10dp"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/shape"
    android:hint="@string/namehint" />

<EditText
    android:id="@+id/edit_phone"
    android:layout_width="290dp"
    android:layout_height="40dp"
    android:layout_below="@id/edit_name"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="12dp"
    android:background="@drawable/shape"
    android:hint="@string/phone"
    android:inputType="phone" />

<EditText
    android:id="@+id/edit_email"
    android:layout_width="290dp"
    android:layout_height="40dp"
    android:layout_below="@id/edit_phone"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="12dp"
    android:background="@drawable/shape"
    android:hint="@string/email"
    android:inputType="textEmailAddress" />

<Spinner
    android:id="@+id/Spinner"
    android:layout_width="290dp"
    android:layout_height="40dp"
    android:layout_below="@id/edit_email"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="12dp"
    android:background="@drawable/shape" >
</Spinner>

<EditText
    android:id="@+id/message"
    android:layout_width="290dp"
    android:layout_height="100dp"
    android:layout_below="@id/Spinner"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="12dp"
    android:background="@drawable/shape"
    android:inputType="text" />

<Button
    android:id="@+id/submit"
    android:layout_width="90dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/message"
    android:layout_marginLeft="105dp"
    android:layout_marginTop="12dp"
    android:background="@drawable/newshape"
    android:text="@string/submit"
    android:textSize="18sp"
    android:textStyle="normal" />

package com.ons.relihealth;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
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 contactus extends Activity implements OnItemSelectedListener  {

    EditText edit_name, edit_phone, edit_email, message;
    Button submit;
    Spinner spinner;
    List<String> list;
    String item;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contactus);

        edit_name= (EditText)findViewById(R.id.edit_name);
        edit_phone= (EditText)findViewById(R.id.edit_phone);
        edit_email= (EditText)findViewById(R.id.edit_email);
        message= (EditText)findViewById(R.id.message);
        submit= (Button)findViewById(R.id.submit);


        Spinner Spinner = (Spinner) findViewById(R.id.Spinner);
        Spinner.setOnItemSelectedListener(this);

        // Spinner Drop down elements
        List<String> categories = new ArrayList<String>();
        categories.add("Individual Health Plan");
        categories.add("Family Health Plan");
        categories.add("Senior Citizen Plan");
        categories.add("Top Up Plan");
        categories.add("Travel Insurance");
        categories.add("Maternity insurance");
        categories.add("Personal Accident");
        categories.add("Critical Illness Insurance");


    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);

       // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

          // attaching data adapter to spinner
    Spinner.setAdapter(dataAdapter);


    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub          

            Toast.makeText(getApplicationContext(), "Item : "+item +"  edit_name : " +edit_name.getText().toString() + " edit_phone  " +edit_phone.getText().toString() + "  edit_email  "+edit_email.getText().toString()+ "  message", Toast.LENGTH_LONG).show();

        }
    });

    }
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        // TODO Auto-generated method stub

           // On selecting a spinner item
          item = parent.getItemAtPosition(position).toString();
       // Showing selected spinner item
          Toast.makeText(parent.getContext(), "Selected: Item " + item + "", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        // TODO Auto-generated method stub
    }
}
Yash
  • 51
  • 7
  • Have u checked http://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application ? – Sheetal Mohan Sharma Nov 27 '15 at 16:00
  • how can I do it ? For eg: take a website which has contact form, when we hit submit button, I should receive it in my company email or personal mail? – Yash Nov 27 '15 at 16:04
  • Wherever you want to get it. Read some basics here http://www.mkyong.com/android/how-to-send-email-in-android/ – Sheetal Mohan Sharma Nov 27 '15 at 16:09
  • I do not want to send e-mail via intent... I have a input form in my app where clients can send in their queries. on click of submit I should receive the details on my e-mail. No opening e-mail any default e-mail clients..everything in my app itself – Yash Nov 27 '15 at 16:36

1 Answers1

0

When you call Intent, you can think of it equivalent to anchor with mailto.

How do you send details from contact form to your mail id without user intervention normally?

Having a server side script to handle the post request with all the details like message title,body,to address etc. right ?

You should use the same approach in this case too.

Extract values from EditText and make post request to your remote server(if you already have otherwise you need to setup one) and on the server side trigger a mail. (this is quite easy in any server side language)

Note: Since you are dealing everything yourself. Make sure you always handle error cases like Network unavailability or invalid paramters or Internal server error etc and also showing either "Message sent" or "Retry"

Ramesh
  • 1,287
  • 1
  • 9
  • 14
  • fine. I got it. Can I do the same using SMS. Like if I hit a submit button can I get all the details in my SMS? Sry I'm new to android. I may b asking some weird question. Please help. – Yash Nov 28 '15 at 07:26
  • guess this is the easiest way ?? – Yash Nov 28 '15 at 07:27
  • So this depends on your requirement, do you mind user getting charged for this SMS? – Ramesh Nov 28 '15 at 07:29
  • How is normally SMS sent from Android app. 1. if you are ok with sms costing the app user, then you can use SmsManager's sendTextMessage.. google has lot of resources for it. 2. if you dont want to cost user, then you should again post these details to your server and you need to integrate sms gateway and send this message – Ramesh Nov 28 '15 at 09:18
  • did it answer your question? better to have a closure on the thread. – Ramesh Nov 30 '15 at 05:45
  • I couldn't solve this issue last time. I have found the app where contact form and the call option which is exactly how I wanted. please fine the link here https://play.google.com/store/apps/details?id=com.rohancorporation.chillipages&hl=en. Please download. I want the contact form and contact exactly the same. – Yash Dec 12 '15 at 13:19