Advertisement
ChocoMan

Untitled

May 29th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // RETRIEVE LATEST SMS FROM CONTACTS WHO SENT SMS
  2. String folder = "content://sms/inbox/";
  3. Uri mSmsQueryUri = Uri.parse(folder);
  4. List<String> messages = new ArrayList<String>();
  5.  
  6. try{
  7. Cursor c = context.getContentResolver().query(mSmsQueryUri, null, null, null, null);
  8. if(c == null){
  9. Log.i(TAG, "cursor is null. uri: " + mSmsQueryUri);
  10. }
  11. contactName = data.get(position);
  12. for(boolean hasData = c.moveToFirst(); hasData; hasData = c.moveToNext()){
  13. final String body = c.getString(c.getColumnIndexOrThrow("body"));
  14. messages.add(body);
  15. }
  16. }catch(Exception e){
  17. Log.e(TAG, e.getMessage());
  18. }finally{
  19. c.close();
  20. }
  21. holder.latestSMS.setText(messages.get(position)); // Displays last message in listview per contact
  22.  
  23. //END RESULT: within my listview, it displays the just like the inbox on your device of all
  24. // SMS from all contacts who sent a message.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement