|
@@ -15,7 +15,9 @@ import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import com.wdkl.ncs.android.lib.base.BaseApplication;
|
|
|
+import com.wdkl.ncs.android.middleware.common.Constants;
|
|
|
import com.wdkl.ncs.android.middleware.model.ContactItem;
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.PhoneInteractionVO;
|
|
|
import com.wdkl.ncs.android.middleware.model.vo.WatchContactVO;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -78,6 +80,72 @@ public class ContactHelper {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static PhoneInteractionVO getLatestCallLog(final Context context) {
|
|
|
+ Uri callUri = CallLog.Calls.CONTENT_URI;
|
|
|
+ String[] columns = {CallLog.Calls.CACHED_NAME,
|
|
|
+ CallLog.Calls.NUMBER,
|
|
|
+ CallLog.Calls.DATE,
|
|
|
+ CallLog.Calls.DURATION,
|
|
|
+ CallLog.Calls.TYPE};
|
|
|
+ Cursor cursor = null;
|
|
|
+ PhoneInteractionVO interactionVO = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ cursor = context.getContentResolver().query(
|
|
|
+ callUri, // 查询通话记录的URI
|
|
|
+ columns, //数据库列选择 不选则获取所有列
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ CallLog.Calls.DEFAULT_SORT_ORDER //按照时间逆序排列,最近打的最先显示
|
|
|
+ );
|
|
|
+ Log.i(TAG, "cursor count:" + cursor.getCount());
|
|
|
+ if (cursor.moveToNext()) {
|
|
|
+ String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)); //姓名
|
|
|
+ String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)); //号码
|
|
|
+ long dateLong = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)); //获取通话日期
|
|
|
+ String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(dateLong));
|
|
|
+ int duration = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION));//获取通话时长,值为多少秒
|
|
|
+ int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)); //获取通话类型:1.来电 2.去电 3.未接的来电 4.voicemail 5.拒接的来电
|
|
|
+
|
|
|
+ interactionVO = new PhoneInteractionVO();
|
|
|
+ if (type == CallLog.Calls.INCOMING_TYPE || type == CallLog.Calls.MISSED_TYPE || type == CallLog.Calls.REJECTED_TYPE) {
|
|
|
+ //接通的来电,未接的来电,拒接的来电
|
|
|
+ interactionVO.setFromDevicePhoneNumber(number);
|
|
|
+ interactionVO.setToDevicePhoneNumber(Constants.Companion.getPhoneNumber());
|
|
|
+ interactionVO.setToId(Constants.Companion.getDeviceId());
|
|
|
+ } else if (type == CallLog.Calls.OUTGOING_TYPE) {
|
|
|
+ //去电:包括接通的,自己取消的,对方拒接的
|
|
|
+ interactionVO.setFromDevicePhoneNumber(Constants.Companion.getPhoneNumber());
|
|
|
+ interactionVO.setToDevicePhoneNumber(number);
|
|
|
+ interactionVO.setFromId(Constants.Companion.getDeviceId());
|
|
|
+ }
|
|
|
+ interactionVO.setActionStart(dateLong);
|
|
|
+ interactionVO.setActionCallTime(duration);
|
|
|
+ interactionVO.setActionStatus(type);
|
|
|
+ //interactionVO.setActionAccept();
|
|
|
+ //结束时间需要减去延时的时间
|
|
|
+ interactionVO.setActionEnd(System.currentTimeMillis()-1200);
|
|
|
+
|
|
|
+ Log.i(TAG, "Call log: " + "\n"
|
|
|
+ + "name: " + name + "\n"
|
|
|
+ + "date: " + date + "\n"
|
|
|
+ + "phone number: " + number + "\n"
|
|
|
+ + "duration: " + duration + "\n"
|
|
|
+ + "type: " + type
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (cursor != null) {
|
|
|
+ cursor.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return interactionVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 插入手机号
|
|
|
*
|