想要得到联系人的通话记录或者通话时长 有什么方式可以实现 ,看到网上只有这样的一段代码
String str = "";
int type;
long callTime;
Date date;
String time= "";
ContentResolver cr = 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);
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
str = cursor.getString(0);
str = cursor.getString(1);
type = cursor.getInt(2);
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = new Date(Long.parseLong(cursor.getString(3)));
time = sfd.format(date);
}不大懂这代码的意思,我将str和time 打印出来 得到这样的信息 null:1970-01-01 08:00:00 完全不是想要的东西啊
请教大牛指点这段代码
String str = "";
int type;
long callTime;
Date date;
String time= "";
ContentResolver cr = 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);
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
str = cursor.getString(0);
str = cursor.getString(1);
type = cursor.getInt(2);
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = new Date(Long.parseLong(cursor.getString(3)));
time = sfd.format(date);
}不大懂这代码的意思,我将str和time 打印出来 得到这样的信息 null:1970-01-01 08:00:00 完全不是想要的东西啊
请教大牛指点这段代码
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货