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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| /** 读取手机通话记录 type 1呼入 2呼出 3未接*/public static ArrayList<Map<String, Object>> getPhoneRecord(Context context) {ArrayList<Map<String, Object>> record_list = new ArrayList<Map<String, Object>>();Map<String, Object> map = null;String number = null;long time_mills;String currentTime;String callTime;String numberOrName = null;// 电话或者姓名String callDate = null;// 打电话日期int type;// 类型Date date;// 查询通话记录ContentResolver cr = context.getContentResolver();final Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, new String[] {CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME,CallLog.Calls.TYPE, CallLog.Calls.DATE }, null, null,CallLog.Calls.DEFAULT_SORT_ORDER);// 获取系统当前时间SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd");currentTime = sFormat.format(new Date(System.currentTimeMillis()));//遍历获取通话记录 并用List容器存放for (int i = 0; i < cursor.getCount(); i++) {cursor.moveToPosition(i);number = cursor.getString(0);// 电话号码numberOrName = cursor.getString(1);// 名字type = cursor.getInt(2);// 类型time_mills = Long.parseLong(cursor.getString(3));// 打电话的时间SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");date = new Date(time_mills);// 打电话的日期callDate = sfd.format(date);callTime = sFormat.format(time_mills);map = new HashMap<String, Object>();map.put("phone_number", number);//末接if (type == 3) {map.put("call_img", R.drawable.missed);if (currentTime.trim().equals(callTime.trim())) {map.put("type", context.getResources().getString(R.string.today)+ "(" + context.getResources().getString(R.string.missed)+ ")");} else {map.put("type", context.getResources().getString(R.string.before)+ "(" + context.getResources().getString(R.string.missed)+ ")");}}//拨出else if (type == 2) {map.put("call_img", R.drawable.outgoing);if (currentTime.trim().equals(callTime.trim())) {map.put("type", context.getResources().getString(R.string.today)+ "(" + context.getResources().getString(R.string.outgoing)+ ")");} else {map.put("type", context.getResources().getString(R.string.before)+ "(" + context.getResources().getString(R.string.outgoing)+ ")");}//来电} else {map.put("call_img", R.drawable.incoming);if (currentTime.trim().equals(callTime.trim())) {map.put("type", context.getResources().getString(R.string.today)+ "(" + context.getResources().getString(R.string.incoming)+ ")");} else {map.put("type", context.getResources().getString(R.string.before)+ "(" + context.getResources().getString(R.string.incoming)+ ")");}}if (numberOrName == null) {numberOrName = number;}map.put("numberOrName", numberOrName);map.put("callDate", callDate);record_list.add(map);}cursor.close();return record_list;} |
更多知识点的学习,可以到迹涯网 http://www.jiyanet.com
没有评论:
发表评论