Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onReceive(Context context, Intent intent) {
- Intent m=new Intent(context, Receiver.class);
- PendingIntent pi=PendingIntent.getBroadcast(context, 0, m, 0);
- //---get the SMS message passed in---
- Bundle bundle = intent.getExtras();
- SmsMessage[] msgs = null;
- if (bundle != null)
- {
- //---retrieve the SMS message received---
- Object[] pdus = (Object[]) bundle.get("pdus");
- msgs = new SmsMessage[pdus.length];
- for (int i=0; i<msgs.length; i++){
- msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
- number = msgs[i].getOriginatingAddress();
- message = msgs[i].getMessageBody();
- }
- //---display the new SMS message---
- Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
- SmsManager sms = SmsManager.getDefault();
- sms.sendTextMessage(number, null, "Whats up", pi, null);
- }
- }
Add Comment
Please, Sign In to add comment