|
@@ -8,6 +8,7 @@ import android.content.ContentValues;
|
|
|
import android.content.Context;
|
|
|
import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
+import android.provider.CallLog;
|
|
|
import android.provider.ContactsContract;
|
|
|
import android.telephony.TelephonyManager;
|
|
|
import android.text.TextUtils;
|
|
@@ -17,7 +18,9 @@ import com.wdkl.ncs.android.lib.base.BaseApplication;
|
|
|
import com.wdkl.ncs.android.middleware.model.ContactItem;
|
|
|
import com.wdkl.ncs.android.middleware.model.vo.WatchContactVO;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -28,6 +31,53 @@ public class ContactHelper {
|
|
|
|
|
|
private static List<WatchContactVO> contacts = new ArrayList<>();
|
|
|
|
|
|
+ //获取通话记录
|
|
|
+ public static void getCallLogs(Context context) {
|
|
|
+ Uri callUri = CallLog.Calls.CONTENT_URI;
|
|
|
+ Cursor cursor = null;
|
|
|
+ try {
|
|
|
+ cursor = context.getContentResolver().query(callUri, // 查询通话记录的URI
|
|
|
+ //columns, //数据库列选择 不选则获取所有列
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ CallLog.Calls.DEFAULT_SORT_ORDER //按照时间逆序排列,最近打的最先显示
|
|
|
+ );
|
|
|
+ Log.i(TAG, "cursor count:" + cursor.getCount());
|
|
|
+ int i = 0;
|
|
|
+ while (cursor.moveToNext() && i < 20) {
|
|
|
+ i++;
|
|
|
+ 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));
|
|
|
+ //String time = new SimpleDateFormat("HH:mm").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.拒接
|
|
|
+ //String dayCurrent = new SimpleDateFormat("dd").format(new Date());
|
|
|
+ //String dayRecord = new SimpleDateFormat("dd").format(new Date(dateLong));
|
|
|
+ //String phone_account_address = cursor.getString(cursor.getColumnIndex("phone_account_address"));//本机号码可能获取不到(华为、oppo获取不到)
|
|
|
+ //String phone_account_id = cursor.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));//本机sim卡id,即ICCID
|
|
|
+ //String phone_account_hidden = cursor.getString(cursor.getColumnIndex("phone_account_hidden"));
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 插入手机号
|
|
|
*
|