Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. @Override
  2. public void onReceive(Context context, Intent intent) {
  3. Intent m=new Intent(context, Receiver.class);
  4. PendingIntent pi=PendingIntent.getBroadcast(context, 0, m, 0);
  5. //---get the SMS message passed in---
  6. Bundle bundle = intent.getExtras();
  7. SmsMessage[] msgs = null;
  8.  
  9. if (bundle != null)
  10. {
  11. //---retrieve the SMS message received---
  12. Object[] pdus = (Object[]) bundle.get("pdus");
  13. msgs = new SmsMessage[pdus.length];
  14. for (int i=0; i<msgs.length; i++){
  15. msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
  16. number = msgs[i].getOriginatingAddress();
  17.  
  18. message = msgs[i].getMessageBody();
  19.  
  20.  
  21. }
  22. //---display the new SMS message---
  23. Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
  24.  
  25. SmsManager sms = SmsManager.getDefault();
  26. sms.sendTextMessage(number, null, "Whats up", pi, null);
  27. }
  28.  
  29.  
  30. }
Add Comment
Please, Sign In to add comment