package com.coolape.tianrun; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.CallLog; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; public class CallLogUtl { public static List getCallLog(Context context) { List infos = new ArrayList(); ContentResolver cr = context.getContentResolver(); Uri uri = CallLog.Calls.CONTENT_URI; String[] projection = new String[] { CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.TYPE }; SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss"); Cursor cursor = cr.query(uri, projection, null, null, null); while (cursor.moveToNext()) { String number = cursor.getString(0); long date = cursor.getLong(1); int type = cursor.getInt(2); infos.add(new CallLogInfo(number, format.format(date), type)); } cursor.close(); return infos; } public static String getCallLogJson(Context context) { List infos = getCallLog(context); JSONArray array = new JSONArray(); for(int i=0; i < infos.size(); i++){ array.put(infos.get(i).toJson()); } return array.toString(); } }