权限
读取通话记录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
public ArrayList<HashMap<String, Object>> getCallLogList(Context context,
int start,int limitKey) {
// TODO Auto-generated method stub
Date d = new Date();
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss");
Cursor cursor = context.getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, null, null,
CallLog.Calls.DEFAULT_SORT_ORDER + " limit " + start+"," +limitKey);
while (cursor.moveToNext()){
HashMap<String, Object> hm = new HashMap<String, Object>();
//String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
String date = sdf.format(new Date(Long.valueOf(cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE)))));
String status = cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE));
if (status.equals("1")) {
status = Constants.CALL_STATE_FROM_GET;
hm.put("callStateImg", R.drawable.call_state_from);
} else if (status.equals("2")) {
status = Constants.CALL_STATE_TO;
hm.put("callStateImg", R.drawable.call_state_to);
} else {
status = Constants.CALL_STATE_MISSES ;
hm.put("callStateImg", R.drawable.call_state_hangup);
}
String contact_name = GlobalUtil.getContactNameFromPhoneNum(context,number);
if(contact_name!=null && !contact_name.equals("")){
hm.put("name", contact_name);
hm.put("categray", Constants.CATEGRAY_IN_CONTACTS);
hm.put("disp", "联系人");
}else{
hm.put("name", number);
initNumberCateGrayAndInfo(number,hm);
}
hm.put("status", status);
hm.put("number", number);
hm.put("date", date);
hm.put("belongs", this.findNumBelongs(number));
list.add(hm);
}
return list;
}
|
读取短信
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
public ArrayList<HashMap<String, Object>> getMessageLogList(
Context context, int start,int limitKey) {
// TODO Auto-generated method stub
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
String[] projection = new String[] { "_id", "address", "person",
"body", "read", "date" };
Cursor cur = context.getContentResolver()
.query(Uri.parse("content://sms/inbox"), projection, null, null,
"date desc limit " + start+"," +limitKey);
int smsColumn_id = cur.getColumnIndex("_id");
int phoneColumn = cur.getColumnIndex("address");
int smsColumn = cur.getColumnIndex("body");
int readColum = cur.getColumnIndex("read");
int dateColum = cur.getColumnIndex("date");
while (cur.moveToNext()){
// Get the field values
HashMap<String, Object> hm = new HashMap<String, Object>();
String number = cur.getString(phoneColumn);
if(number!=null){
String name = GlobalUtil.getContactByAddr(context,number);
String sms = cur.getString(smsColumn);
String sms_id = cur.getString(smsColumn_id);
int read = cur.getInt(readColum);
String date = cur.getString(dateColum);
SimpleDateFormat sfd = new SimpleDateFormat("MM/dd hh:mm:ss");
Date date_format = new Date(Long.parseLong(date));
String date_time = sfd.format(date_format);
// 还要判断是否存在于本地黑名单、和临时通讯录、还要联系人中
if(name!=null && !name.equals("")){
hm.put("categray", Constants.CATEGRAY_IN_CONTACTS);
hm.put("disp", "联系人");
hm.put("name", name);
}else{
initNumberCateGrayAndInfo(number,hm);
hm.put("name", number);
}
hm.put("number", number);
if(sms!=null && sms.length()>4){
hm.put("short_sms", date_time+"-"+sms.substring(0,4)+"...");
hm.put("sms", sms);
}else if(sms!=null){
hm.put("sms", sms);
hm.put("short_sms", sms);
}else{
hm.put("sms", "");
hm.put("short_sms", "");
}
if(0 == read){//未读
hm.put("read_state", R.drawable.msg_unread);
}else{//已读
hm.put("read_state", R.drawable.msg_read);
}
hm.put("read", read+"");
hm.put("date", date_time + "");
hm.put("sms_id", sms_id + "");
hm.put("belongs", findNumBelongs(number));
list.add(hm);
}
}
return list;
}
|
没有评论:
发表评论