1

I improve my app with jokes and I have problem. I would like to add "send by sms button" and i would like to send text in TextView through SMS (If user choose joke and he will want send by SMS).

How Can I do that?

Beska
  • 12,445
  • 14
  • 77
  • 112
Tomeksss
  • 303
  • 2
  • 4
  • 11

2 Answers2

1

1. Integrating SMS Manager Inside your App

Add permission in your manifest file::

 <uses-permission android:name="android.permission.SEND_SMS"/>

 sendMySmsBtn=(Button)findViewById(R.id.send);
 sendMySmsBtn.setonclickListener(new OnClickListener(){
 public void Onclick()
   {
    sendSMS("99999999999", "message");
   });


  private void sendSMS(String phoneNumber, String message)
   {        
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message,null, null);        
   }  

2. Intenting SMS Application installed in your device

  int phoneNumber=9999999999; 
  Intent startSmsApp=new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
                    + phoneNumber);
  startSmsApp.putExtra("sms_body", message);
  startActivity(startSmsApp);
Community
  • 1
  • 1
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
-1

See Send SMS in android. It is not possible to send Texts automaticly, Android secured that function. This code will start an Intent to the SMS send applicataion:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
                        + phoneNumber)));

Also see this tutorial and this tutorial.

Community
  • 1
  • 1
ObAt
  • 2,337
  • 3
  • 24
  • 44
  • 3
    downvoted for very wrong information. SmsManager is what you use to send SMSs. Any app can ask the permission for that. (Which is more amazing is, your first tutorial link shows just that) – njzk2 Jan 03 '13 at 16:58