Hello Marcin Orlowski,
Thanks for reply. This is my following code
that sends sms and that sms receive the destination mobile.it works well.
It display the msg on destination mobile.But I dont understand
where do i write code that read message on receviers mobile
and determine particular word like "abc" that will call webservice.
plz help .......Thanks in advanced.
public class SmswithwebserviceActivity extends Activity { /**
Called when the activity is first created. */
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;
Pattern pattern;
Matcher matcher;
Context c;
// smsreceiveandcallwebservice srcws=new smsreceiveandcallwebservice();
/** Called when the activity is first created. */
//@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.bt1);
txtPhoneNo = (EditText) findViewById(R.id.etp1);
txtMessage = (EditText) findViewById(R.id.etm1);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String phoneNo = txtPhoneNo.getText().toString();
String message =
txtMessage.getText().toString();
if (phoneNo.length()>0 &&
message.length()>0)
sendSMS(phoneNo, message);
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
});
}
private void sendSMS(String phoneNumber, String message)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
// SmsManager sms = SmsManager.getDefault();
// sms.sendTextMessage(phoneNumber, null, message, null, null);
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
// ---when the SMS has been sent---//
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not
delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI,
deliveredPI);
}
}
On Sunday, 18 March 2012 00:03:11 UTC+5:30, Marcin Orlowski wrote:
>
> Register for SMS broadcasts. Once you got SMS, get the mesaage body and
> parse its content. if you wind what you look for, then fire up the code
> talking to web service.
>
> Regards,
> Marcin Orlowski
>
> *Tray Agenda <http://bit.ly/trayagenda>* - keep you daily schedule
> handy...
> *Date In Tray* <http://bit.ly/dateintraypro> - current date at glance...
> WebnetMobile on *Facebook <http://webnetmobile.com/fb/>*,
> *Google+*<http://bit.ly/webnetmobile-gp>and
> *Twitter <http://webnetmobile.com/twitter/>*
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en