-4

I would like to know how can I send a sms getting the textview information with one button , I dont need receive message , only send the textview information clicking the button for a specific number

Darek Kay
  • 15,827
  • 7
  • 64
  • 61
  • 2
    Please, be more specific. You should provide relevant snippets of code, layouts, etc. Have a look at [how-to-ask](https://stackoverflow.com/help/how-to-ask). Also, have a detailed look at [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Xavier Rubio Jansana Jan 03 '18 at 13:52
  • 1
    What have you tried so far? Have you read about Intents? – O.O.Balance Jan 03 '18 at 13:52

1 Answers1

2

What have you done so far? I would suggest using an implicit intent that triggers an sms client in your phone when the button is clicked, like this:

Uri smsUri = Uri.parse("tel:123456");
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("sms_body", "sms text");
intent.setType("vnd.android-dir/mms-sms"); 
startActivity(intent);

"sms text" should be your textView text. You can do something like this instead

yourTextView.getText().toString();
Ege Kuzubasioglu
  • 5,991
  • 12
  • 49
  • 85
  • Button sendtext = (Button) findViewById(R.id.sendtext); sendtext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Uri smsUri = Uri.parse("tek:999"); Intent intent = new Intent(Intent.ACTION_VIEW,smsUri); intent.putExtra("sms_body", textViewew1.getText().toString()); intent.setType("vnd.android-dir/mms-sms"); startActivity(intent); } }); } } – Jonathan Reyes Jan 03 '18 at 15:23
  • I did this but does not work i receive error when i click de button – Jonathan Reyes Jan 03 '18 at 15:24
  • Ok I resolve the problem thanks so much – Jonathan Reyes Jan 03 '18 at 16:56
  • no worries, you can accept the answer as correct – Ege Kuzubasioglu Jan 03 '18 at 17:59
  • For sure but before I would like to know how i can separate the different text view ,because when i see in the message on the phone all.is together i have to use /n or something like that? – Jonathan Reyes Jan 03 '18 at 18:01
  • Do you mean splitting as sentences? https://stackoverflow.com/a/30337292/6683139 – Ege Kuzubasioglu Jan 03 '18 at 18:07
  • Its ok I rosolve the space problem between variable with some +""+ , I would like to know if is possible send the message to the default phone number, because when i put some nunber kn this lane Uri sms Uri = Uri.parse ("tel:1234"); I have to put the number when the intent start . – Jonathan Reyes Jan 03 '18 at 18:42