0

I have to take data from user and on-submit button i have to send that data on predefined email address

I dont want to go to this option i want to send it directly on a submit button without more user interaction

output of my current code

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Arrays;
import java.util.List;

public class AddSP extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_sp);
        final Button send = (Button) this.findViewById(R.id.button6);

        send.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {


                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"m.awa@gmail.com"});
                i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
                i.putExtra(Intent.EXTRA_TEXT   , "body of email");
                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(AddSP.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Stack Overflow is for programming questions. What is your question? If your question is "how do I do this?", please explain what you have tried and what specific problems that you have encountered. – CommonsWare Apr 25 '17 at 14:17
  • good for you. did you have a question? – njzk2 Apr 25 '17 at 14:18
  • yes ! i am new to android how i can send that data on my defined email address which i have collected from user in edittext – awais ashraf Apr 25 '17 at 14:20
  • @CommonsWare What should i do in java class ? through which i can send data on my defined email address – awais ashraf Apr 25 '17 at 14:23
  • 1
    When you searched for information on how to send email in an Android app, what did you learn? For example, there are several Stack Overflow questions in the "Related" column on the side of this page that seem to cover this topic, such as [this one](http://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application). Many of those would have been suggested to you when you were writing this question. If you tried something, and you were having problems with it, ask a separate Stack Overflow question with a [mcve] explaining what you tried and what problems you have. – CommonsWare Apr 25 '17 at 14:27
  • my current code is taking me on another screen of mailing application but i dont want to go there i want to subimt the data on button click to my defined email address thats what i am not getting anywhere – awais ashraf Apr 25 '17 at 16:01
  • You will need to use an actual java emailing library, then as `Intent.ACTION_SEND` will start an send intent to the OS, which is a user-controlled setting *which app* controls the data. Note: Asking for a library is off topic for StackOverflow – OneCricketeer Apr 25 '17 at 16:46

0 Answers0