3
A
回答
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
也要看這是否太問題How can I read SMS messages from the inbox programmatically in Android?
相關問題
- 1. 如何顯示錶單中的信息?
- 2. 如何使用列表顯示列中某個人的信息?
- 3. 顯示錶A中的所有信息,如果一列行帳號匹配
- 4. 如何顯示opencart模塊中的所有產品信息?
- 5. 顯示所有的原始信息
- 6. 顯示錶中所有信息的搜索結果
- 7. 顯示所有註冊用戶信息
- 8. 顯示與data.info所有信息()在Python
- 9. TableLayoutPanel Winforms不顯示所有信息
- 10. 在列表框中顯示消息框中的多個信息
- 11. 如何顯示Eclipse中的所有列?
- 12. 如何顯示沒有管理員列表中的所有WordPress用戶與用戶信息
- 13. 如何選擇整個數據庫並顯示所有信息
- 14. 如何顯示所有信息從SQL查詢
- 15. 如何正確設置循環以顯示所有信息
- 16. 如何在條件存在時按信息顯示所有組?
- 17. Libcurl如何不顯示所有這些信息
- 18. PHP 5.5 php.ini - 如何配置顯示所有錯誤信息
- 19. 如何顯示錶中的所有值
- 20. 如何在列表視圖中顯示錶的所有記錄?
- 21. 如何將信息輸入一系列表格並顯示該信息?
- 22. 文章列表還顯示查看所有文章的數據庫信息
- 23. 如何獲得我所有時間的所有Facebook狀態信息的列表?
- 24. 如何顯示錶格中的所有數據(並且不顯示頁腳信息)?
- 25. 如何顯示來自陣列的所有消息的警報
- 26. 如何在兩張表格中顯示錶格上的信息?
- 27. 如何在sql中顯示多個表中的所有列?
- 28. 顯示所需的屬性信息
- 29. 顯示多列的列信息
- 30. 如何獲取有關Oracle中某個表的所有信息?