title: Insert predefined message into existing conversation (Android)
body: <p>Is there any way that I can insert a predefined message into an existing conversation in the inbox from an app built on the Android platform?</p>
  
  <p>With this code I am able to retrieve the last sent and received messages.</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  TextView tv = new TextView(this);
  
  Uri uriSMS = Uri.parse("content://sms/");
  Cursor cur = getContentResolver().query(uriSMS, null, null, null, null);
  cur.moveToNext();
  
  String body = cur.getString(cur.getColumnIndex("body"));   
  String add = cur.getString(cur.getColumnIndex("address"));
  String time = cur.getString(cur.getColumnIndex("date"));
  String protocol = cur.getString(cur.getColumnIndex("protocol"));       
  
  String contactName = "";
  Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(add));  
  Cursor c = getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null );  
  if( c.moveToFirst() ) {  
               int nameIndex = c.getColumnIndex(PhoneLookup.DISPLAY_NAME);  
               contactName = c.getString(nameIndex);
  }
  c.close();
  cur.close();
  
  String out = "";
  Date d = new Date(Long.valueOf(time)); 
  
  if (protocol == null)
      out = "Sending to: "+ contactName + " &lt;"+add +"&gt;\nDate: "+d +"\nBody: "+body+"\n\n";
  else 
      out = "Received from: "+ contactName + " &lt;"+add +"&gt;\nDate: "+d +"\nBody: "+body+"\n\n";
  
  tv.setText(out);
  setContentView(tv);
  
  }
  </code></pre>
  
  <p>Is there any way that I can incorporate this into my broadcast receiver (SmsReceiver.java)? Hopefully there is a way that I can trigger an event so that when a new message is received I can insert a predefined message into the conversation related to the newest text message in the inbox.</p>
  
  <p>While I'm at it. Is there any way to accurately retrive the native phone number without asking the user to enter it manually?</p>