title: Android sending sms
body: <p>In my app, there is list containing phone contacts. When user clicks on a contact, he can choose from a menu to send an sms to the contact (or email, or other things).</p>
  
  <pre><code>Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
                      while(people.moveToNext()) {
                        int nameFieldColumnIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
                        String contact = people.getString(nameFieldColumnIndex);
                        int numberFieldColumnIndex = people.getColumnIndex(PhoneLookup.NUMBER);
                        String number = people.getString(numberFieldColumnIndex);
                          if (contact.equals(myArr2_cs[item]))
                              {
                              Intent int_sms = new Intent(Intent.ACTION_SEND);
                              int_sms.setType("text/plain");
                              int_sms.putExtra(Intent.EXTRA_EMAIL  , new String[]{number});
                              int_sms.putExtra(Intent.EXTRA_SUBJECT, "");
                              int_sms.putExtra(Intent.EXTRA_TEXT, "");
                              try {
                                 startActivity(Intent.createChooser(int_sms, "Sending SMS.."));
                              } catch (android.content.ActivityNotFoundException ex) {
                                 Toast.makeText(MainActivity.this, "No installed sms clients found", Toast.LENGTH_SHORT).show();
                              }
  </code></pre>
  
  <p>The intent part is designed for sending e-mail - it shows user a list to choose from clients, which is what i want.
  You see there are two variables for the contact name and the phone number.
  User clicks on a name of the list then clicks on send sms, a pop up list appears to choose from sms, email, bluetooth etc. I choose go sms or any other installed sms app from the pop up list, the client appears with the fields (to, text) empty. I want the number to appear in the sms box of the sms form. So if user clicks on "Tom Jones" and then clicks on "send sms", Tom Jones'number should already be filled in the client. My code does not do this.</p>
  
  <p>I also tried sending sms with these lines, but they resulted in force close:</p>
  
  <pre><code>SmsManager sm = SmsManager.getDefault();
  String number2 = "6508570720";//this should the number variable
  sm.sendTextMessage(number2, null, "Test SMS Message", null, null);
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>Intent sendIntent= new Intent(Intent.ACTION_VIEW);
  sendIntent.putExtra("sms_body", "smsBody");
  sendIntent.putExtra("address", number);
  sendIntent.setType("vnd.android-dir/mms-sms");
  startActivity(sendIntent);
  </code></pre>