Advertisement
Guest User

Untitled

a guest
Apr 7th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public class SMSReceiverActivity extends ListActivity {
  2. private BroadcastReceiver mIntentReceiver;
  3. ListView listview;
  4. ArrayAdapter<String> arrayAdpt;
  5. @Override
  6. public void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_smsreceiver);
  9.  
  10. listview=this.getListView();
  11. }
  12.  
  13. @Override
  14. protected void onResume() {
  15. super.onResume();
  16.  
  17. IntentFilter intentFilter = new IntentFilter("SmsMessage.intent.MAIN");
  18. mIntentReceiver = new BroadcastReceiver() {
  19. @Override
  20. public void onReceive(Context context, Intent intent) {
  21. String msg = intent.getStringExtra("get_msg");
  22.  
  23. //Process the sms format and extract body &amp; phoneNumber
  24. msg = msg.replace("\n", "");
  25. String body = msg.substring(msg.lastIndexOf(":")+1, msg.length());
  26. String pNumber = msg.substring(0,msg.lastIndexOf(":"));
  27.  
  28. //Add it to the list or do whatever you wish to
  29. TextView text = (TextView) findViewById(R.id.editText1);
  30. text.setText(body);
  31. ArrayList<String> bodyarr=new ArrayList<String>();
  32. bodyarr.add(body);
  33. arrayAdpt = new ArrayAdapter<String>(SMSReceiverActivity.this, android.R.layout.simple_list_item_1,
  34. bodyarr);
  35. }
  36. };
  37.  
  38. this.registerReceiver(mIntentReceiver, intentFilter);
  39. }
  40.  
  41. @Override
  42. protected void onPause() {
  43. super.onPause();
  44. this.unregisterReceiver(this.mIntentReceiver);
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement