//獲取當(dāng)前的手機(jī)號
public String getLocalNumber() { Context context = getApplicationContext(); TelephonyManager tManager = (TelephonyManager)context.getSystemService(TELEPHONY_SERVICE); String number = tManager.getLine1Number(); return number; } //刪除通話記錄 private void DeleteCall() { getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER+"=?" , new String[]{"13078943473"}); } //修改通話記錄 private void ModifyCall() { ContentValues content = new ContentValues(); content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE); content.put(CallLog.Calls.NUMBER,"13078945773"); content.put(CallLog.Calls.DATE, 123123123); content.put(CallLog.Calls.NEW, "1");//0已看1未看 getContentResolver().update(CallLog.Calls.CONTENT_URI, content,CallLog.Calls.NUMBER+"=?" , new String[]{"13078943473"}); } //添加通話記錄 private void AddCall() {
ContentValues content = new ContentValues(); content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE); content.put(CallLog.Calls.NUMBER,"13078945773"); content.put(CallLog.Calls.DATE, 123123123); content.put(CallLog.Calls.NEW, "1");//0已看1未看 getContentResolver().insert(CallLog.Calls.CONTENT_URI, content);
} //查詢通話記錄 private void GetCall() { Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER); if(!cursor.moveToFirst()) { Log.i("通話記錄","目前沒有通話記錄"); return; } do { Cursor cur = getContentResolver().query(CallLog.Calls.CONTENT_URI,null, null, null, null); int numIndex = cur.getColumnIndex(CallLog.Calls.NUMBER); int typeIndex = cur.getColumnIndex(CallLog.Calls.TYPE); String phoneNum= null; phoneNum = cur.getString(numIndex);
switch(typeIndex) { case 1://撥入 Toast.makeText(context, "撥入電話:"+phoneNum, Toast.LENGTH_SHORT).show(); Log.i("CALL","1:"+phoneNum); break; case 2://撥出 Toast.makeText(context, "撥出電話:"+phoneNum, Toast.LENGTH_SHORT).show(); Log.i("CALL","2:"+phoneNum); break; case 3://未接 Toast.makeText(context, "未接電話:"+phoneNum, Toast.LENGTH_SHORT).show(); Log.i("CALL","3:"+phoneNum); break; default: Log.i("CALL","defalut"); break; } /* new String[]{CallLog.Calls..CommonDataKinds.Nickname.NAME}, ContactsContract.CommonDataKinds.Nickname.CONTACT_ID+"="+contactId+" AND "+ ContactsContract.Data.MIMETYPE+"='"+ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE+"'", */ }while(cursor.moveToNext()); } |
|