這是我獲得短信的方式,它的效果很好。有發送和接收的單獨日誌。某些第三方SMS程序消息可能不顯示。它會查找從名爲phoneNumbers的字符串中的號碼發送或接收的SMS,並將所有找到的SMS消息添加到數組中進行處理。
public void getSMS(){
final String[] projection = null;
final String selection = "address IN (" + phoneNumbers + ")";
final String selectionArgs[] = null;
final String sortOrder = null;
Cursor c = null;
c = getContentResolver().query(
Uri.parse("content://sms/sent"),
projection,
selection,
selectionArgs,
sortOrder);
if (c.moveToFirst() && c.isNull(c.getColumnIndex("date"))==false && c.isNull(c.getColumnIndex("address"))==false) {
do {
CCall call = new CCall(c.getLong(c.getColumnIndex("date")),c.getString(c.getColumnIndex("address")),4,0);
arrCall.add(call);
} while (c.moveToNext());
}
c = getContentResolver().query(
Uri.parse("content://sms/inbox"),
projection,
selection,
selectionArgs,
sortOrder);
if (c.moveToFirst() && c.isNull(c.getColumnIndex("date"))==false && c.isNull(c.getColumnIndex("address"))==false) {
do {
CCall call = new CCall(c.getLong(c.getColumnIndex("date")),c.getString(c.getColumnIndex("address")),5,0);
arrCall.add(call);
} while (c.moveToNext());
}
c.close();
}
任何想法如何找出哪些聯繫人發送了最後幾條短信? – ycomp 2012-02-10 01:33:52