String [] phoneItem = new String[]{"12599802004","95280371","01053902263","12599802004","95280360","125909818006","01053902251","125909818003","125909818004","125909818007","95280361","95280367","95701419","125909888323","95280365","95280323","95280310","95280395","95280335","051568034003","051568034001","051568034021","0515680340123","05156803400300","05156803400385","05156803400346","05156803400388","05156803400355"};
insertCallLog(phoneItem[1],"0","3","0");
权限:
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
/* * 插入一条通话记录 * @param number 通话号码 * @param duration 通话时长(响铃时长)以秒为单位 1分30秒则输入90 * @param type 通话类型 1呼入 2呼出 3未接 * @param isNew 是否已查看 0已看1未看 */ private void insertCallLog(String number, String duration, String type, String isNew) {
ContentValues values = new ContentValues();
values.put(CallLog.Calls.NUMBER, number);
values.put(CallLog.Calls.DATE, System.currentTimeMillis() );
values.put(CallLog.Calls.DURATION, duration);
values.put(CallLog.Calls.TYPE, type);
values.put(CallLog.Calls.NEW, isNew); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_CALL_LOG}, 1000);
}
getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);
}
发表评论: