-2

I am creating an app in which I ahave an activiy in which there is an EditText where one can enter data. I want to send that data on click of a button to other person via services such as mail,messaging,social Apps.I was trying ti di this via Implicit Intents but my data is not visibe in other app. How to do so? My MainAcitivity code is as follows:

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

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

  Button bt=(Button) findViewById(R.id.bt);
        bt.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v) {
                Intent i=new Intent();
                i.setAction(Intent.ACTION_SEND);
                i.setType("text/plain");
                EditText et=(EditText) findViewById(R.id.et);
                String text=et.getText().toString();
                i.putExtra("name",text);
                if (i.resolveActivity(getPackageManager()) != null) {
                    startActivity(i);
                }



                }
            }
        );
    }
}
Ankit
  • 21
  • 6

2 Answers2

0

Try doing it like this:

EditText text;
Button btnSave;
String emailstring;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_checking_intent);
    text = (EditText) findViewById(R.id.email);
    btnSave = (Button) findViewById(R.id.button);
    btnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            emailstring = text.getText().toString();
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "subject of your email");
            i.putExtra(Intent.EXTRA_TEXT   , emailstring);
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(CheckingIntent.this, "There are no email app installed.", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Haris ali
  • 773
  • 1
  • 13
  • 19
0

try like this

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   Button button=(Button)findViewById(R.id.button2);
  final   EditText editText=(EditText)findViewById(R.id.editText);

   button.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           Intent intent =new Intent(Intent.ACTION_SEND);
           intent.setType("text/plain");
           intent.putExtra(Intent.EXTRA_TEXT,editText.getText().toString());
           startActivity(intent);
       }
   });
}

}