3

i am new to android.

i am developing one application related to send and receiving sms.

i want to display all receiving sms in a list.

if any one know please help me

thanks in advance.

kiran
  • 3,244
  • 7
  • 34
  • 57

2 Answers2

2

try this:

/* location of sms inbox*/

public static final String CONTENT = "content://sms/inbox";
/*location of sms on sim card */
public static final String SIMCONTENT = "content://sms/sim";
/*name of address field*/
public static final String ADDRESS = "address";
/*name of body field*/
public static final String BODY = "body";

/*cursor incoming sms*/
private static Cursor inboxCursor;
/*cursor sms on sim card*/
private static Cursor simCursor;

   initCursors(Context context){
        inboxCursor = context.getContentResolver()
                        .query(Uri.parse(CONTENT), null, null, null, null);
        simCursor = context.getContentResolver()
                        .query(Uri.parse(SIMCONTENT), null, null, null, null);  
}

 /**
  * Reading SMS from telephone memory.
  * @return a Map object where key - telephone number, value - a  List 
  * consisting of messages.
  */
public Map<String, List<String>> readTelephoneSms() {
    Map<String, List<String>> smsData = new HashMap<String, List<String>>();
    while (inboxCursor.moveToNext()) { 
        if(smsData.containsKey(inboxCursor.getString(inboxCursor.getColumnIndex(ADDRESS)))){
            smsData.get(inboxCursor.getString(inboxCursor.getColumnIndex(ADDRESS)))
                    .add(inboxCursor.getString(inboxCursor.getColumnIndexOrThrow(BODY)));
        }else{
            List<String> data = new ArrayList<String>();
            data.add(inboxCursor.getString(inboxCursor.getColumnIndexOrThrow(BODY)));
            smsData.put(inboxCursor.getString(inboxCursor.getColumnIndex(ADDRESS)), data);
        }
    }

    return smsData;
}

/**
  * Reading SMS from Sim card memory.
  * @return a Map object where key - telephone number, value - a  List
  * consisting of messages.
  */
public Map<String, List<String>> readSimSms() {
    Map<String, List<String>> smsData = new HashMap<String, List<String>>();
  while (simCursor.moveToNext()) { 
    if(smsData.containsKey(simCursor.getString(simCursor.getColumnIndex(ADDRESS)))){
        smsData.get(simCursor.getString(simCursor.getColumnIndex(ADDRESS)))
                .add(simCursor.getString(simCursor.getColumnIndexOrThrow(BODY)));
    }else{
        List<String> data = new ArrayList<String>();
        data.add(simCursor.getString(simCursor.getColumnIndexOrThrow(BODY)));
        smsData.put(simCursor.getString(simCursor.getColumnIndex(ADDRESS)), data);
    }           
}
    return smsData;
}
user370305
  • 108,599
  • 23
  • 164
  • 151
Natali
  • 2,934
  • 4
  • 39
  • 53
2

Its some long stuff for do that...

I just provided you these links, Its fulfill your need what you want. Just look at that and let me know whether its help you or not..

FrontPage/Tutorials/SMS Messaging

android-smspopup

Also look at this SO question How can I read SMS messages from the inbox programmatically in Android?

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151