2012-01-10 15 views

答えて

2

これを試してみてください。

/* 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; 
} 
2

そのいくつかの長いもの、私はちょうどあなたが何をしたいあなたのニーズを満たす。その、あなたにこれらのリンクを提供

...それを行うため。ちょうどその時に見て、私はその助けますか...

FrontPage/Tutorials/SMS Messagingまた

android-smspopup

これを見ては、SO質問するかどうかを知っているようHow can I read SMS messages from the inbox programmatically in Android?

関連する問題