Guest User

Untitled

a guest
May 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public class MySMSBroadCastReceiver extends BroadcastReceiver {
  2. String specificPhoneNumber = "+989033001001";//phNum .Sender
  3.  
  4. @Override
  5. public void onReceive(Context context, Intent intent) {
  6.  
  7. // Get Bundle object contained in the SMS intent passed in
  8. //---get the SMS message passed in---
  9. Bundle bundle = intent.getExtras();
  10. SmsMessage[] smsm = null;
  11. String sms_str = "";
  12.  
  13. if (bundle != null) {
  14. // Get the SMS message
  15. //---retrieve the SMS message received---
  16.  
  17. Object[] pdus = (Object[]) bundle.get("pdus"); //pdus
  18. smsm = new SmsMessage[pdus.length];
  19. for (int i = 0; i < smsm.length; i++) {
  20. smsm[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
  21.  
  22. sms_str += smsm[i].getMessageBody().toString();
  23. String Sender = smsm[i].getOriginatingAddress();
  24. if (specificPhoneNumber.equals(Sender))
  25. {
  26. Uri uri = Uri.parse("content://sms/inbox");
  27. ContentResolver contentResolver = context.getContentResolver();
  28. String where = "address="+Sender;
  29. Cursor cursor = contentResolver.query(uri, new String[] { "_id", "thread_id"}, where, null,
  30. null);
  31. while (cursor.moveToNext())
  32. {
  33. long thread_id = cursor.getLong(1);
  34. where = "thread_id="+thread_id;
  35. Uri thread = Uri.parse("content://sms/inbox");
  36. context.getContentResolver().delete(thread, where, null);
  37. }
  38.  
  39. if (sms_str == "333")
  40. {
  41. Toast.makeText(context,"ั‚ะตัั‚", Toast.LENGTH_LONG).show();
  42. }else
  43. {
  44. Toast.makeText(context, sms_str, Toast.LENGTH_LONG).show();
  45. }
  46.  
  47. Intent l = new Intent(context,SmsReport.class);
  48. l.putExtra("msg",sms_str); //Transfer Data Between Activities Using Intent
  49. l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  50. abortBroadcast();
  51.  
  52. }
  53. }
  54. }
  55. }
  56.  
  57. }
Add Comment
Please, Sign In to add comment