android 通訊錄的增刪改查

來源:互聯網
上載者:User

 *

         * 擷取當前的手機號

         */

        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());

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.