String str = null; String strNumber,strName = ""; int type; long callTime; Date date; String time= ""; ContentResolver cr = getContentResolver(); final Cursor cursor = crquery(CallLogCallsCONTENT_URI, new String[]{CallLogCallsNUMBER,CallLogCallsCACHED_NAME,CallLogCallsTYPE, CallLogCallsDATE,CallLogCallsDURATION}, null, null,CallLogCallsDEFAULT_SORT_ORDER); cursormoveToPosition(0); do{ strNumber = cursorgetString(0); //呼叫号码 strName = cursorgetString(1); //联系人姓名 type = cursorgetInt(2); //来电:1,拨出:2,未接:3 public static final int INCOMING_TYPE = 1; public static final int OUTGOING_TYPE = 2; public static final int MISSED_TYPE = 3; if(type == 1){ str = "来电"; }else if(type == 2){ str = "拨出"; }else if(type == 3){ str = "未接"; } long duration = cursorgetLong(4); //通话时间 SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); date = new Date(LongparseLong(cursorgetString(3))); time = sfdformat(date); smsBuilder1append(strNumber+","); smsBuilder1append(strName+","); smsBuilder1append(str+","); smsBuilder1append(duration+","); smsBuilder1append(time+"\n"); }while(cursormoveToNext()); textView2setText(smsBuilder1toString());
添加权限:
<uses-permission android:name="androidpermissionCALL_PHONE"/> <uses-permission android:name="androidpermissionREAD_CALL_LOG"/> <uses-permission android:name="androidpermissionWRITE_CALL_LOG"/>
以MIUI系统为例,来说明一下查看安卓40通话记录步骤:
1、打开手机系统中的"电话"应用。
2、在电话应用界面,将手机屏幕界面向上滑动即可看到通话记录。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)