1

我正在尝试加载所有 SIM 发送的 SMS 消息,但我不知道除了 “content://sms/icc”和“content://sms/sim”之外的内容提供商 URI 是什么,并且这些 uris 仅加载收到的消息。

如何加载 SIM 卡已发送消息?

4

2 回答 2

1

使用此代码

它对我有用,它会帮助你阅读SMS

 /* 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;
}
于 2013-01-12T12:20:22.763 回答
0

您可以使用此 URI 在 android中访问已发送的消息。


Uri sentURI = Uri.parse("content://sms/sent");


于 2015-04-11T04:56:16.693 回答