title: Triggering a post to a MySQL on incoming SMS
body: <p>I'm working on an Android app and I need to to post to a PHP form or insert into a MySQL database when an incoming message is received. Some of you may be hesitating to respond, but let me assure you that this isn't a malicious app.</p>
  
  <p>The code that I'm posting below is what I'm using to block incoming messages, except from one number. Would anyone be able to help me figure out a way to trigger a post to my server when the text message is blocked?</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.telephony.SmsMessage;
  import android.widget.Toast;
  
  public class SmsReceiver extends BroadcastReceiver {
  
  public static int MSG_TPE=0;
  private String getAddress;
  public void onReceive(Context context, Intent intent) { 
      String MSG_TYPE=intent.getAction();
          if(MSG_TYPE.equals("android.provider.Telephony.SMS_RECEIVED")) {
              Toast received = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);
              received.show();
  
                  Bundle bundle = intent.getExtras();
                  Object messages[] = (Object[]) bundle.get("pdus");
                  SmsMessage smsMessage[] = new SmsMessage[messages.length];
                  for (int n = 0; n &lt; messages.length; n++) {
                      smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
                  }
  
                      getAddress = smsMessage[0].getOriginatingAddress();
                      if(getAddress.equals("APPROVEDPHONENUMBER")) {
                          Toast approved = Toast.makeText(context,"Approved SMS from: " + smsMessage[0].getOriginatingAddress(), Toast.LENGTH_LONG);
                          approved.show();
                              // Message is approved and let through
                      } else {
                          Toast blocked = Toast.makeText(context,"Blocked SMS from: " + smsMessage[0].getOriginatingAddress(), Toast.LENGTH_LONG);
                          blocked.show();
                              // Post to MySQL database
                              abortBroadcast();
                      }
                          for(int i=0;i&lt;8;i++) {
                              System.out.println("Blocking SMS");
                          }
  
          }
  
  }
  
  }
  </code></pre>
  
  <p>Basically what I'm wanting to do is post to an external PHP form from within the app when an event is fired.</p>