Guest User

Untitled

a guest
Jan 22nd, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. try {
  2. Uri uriInbox = Uri.parse("content://sms/inbox");
  3.  
  4. Cursor inbox = getContentResolver().query(uriInbox, null, "address IS NOT NULL) GROUP BY (thread_id", null, null); // 2nd null = "address IS NOT NULL) GROUP BY (address"
  5. Uri uriSent = Uri.parse("content://sms/sent");
  6. Cursor sent = getContentResolver().query(uriSent, null, "address IS NOT NULL) GROUP BY (thread_id", null, null); // 2nd null = "address IS NOT NULL) GROUP BY (address"
  7. Cursor c = new MergeCursor(new Cursor[]{inbox,sent}); // Attaching inbox and sent sms
  8.  
  9. if (c.moveToFirst()) {
  10. for (int i = 0; i < c.getCount(); i++) {
  11. String name = null;
  12. String phone = "";
  13. String _id = c.getString(c.getColumnIndexOrThrow("_id"));
  14. String thread_id = c.getString(c.getColumnIndexOrThrow("thread_id"));
  15. String msg = c.getString(c.getColumnIndexOrThrow("body"));
  16. String type = c.getString(c.getColumnIndexOrThrow("type"));
  17. String timestamp = c.getString(c.getColumnIndexOrThrow("date"));
  18. phone = c.getString(c.getColumnIndexOrThrow("address"));
  19.  
  20. if(name == null)
  21. {
  22. name = Function.getContactByPhoneNumber(getApplicationContext(), c.getString(c.getColumnIndexOrThrow("address")));
  23. }
  24.  
  25. tmpList.add(Function.mappingInbox(_id, thread_id, name, phone, msg, type));
  26. c.moveToNext();
  27. }
  28. }
  29. c.close();
Add Comment
Please, Sign In to add comment