㈠ 如何修改android手機通訊錄、設置、通話記錄、聯系人等界面的背景顏色與字體顏色。
聯系人倒是可以直接點擊編輯,上傳本地圖片設置背景。
㈡ android 通訊錄 怎麼改聯系人
通過getContentResolver()得到ContentResolver
後,我們就可以通過該對象的delete,insert,updata,query等方法間接操作聯系人資料庫,那麼,如果我們刪除某些聯系人,以ContactsContract.RawContacts.CONTENT_URI為例,怎麼做,先來看下源碼:
首先,ContentResolver調用delete();刪除操作從紅色部分開始
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
waitForAccess();
return super.delete(uri, selection, selectionArgs);
}
上面的super.delete(uri, selection, selectionArgs)調用父親方法
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
boolean applyingBatch = applyingBatch();
if (!applyingBatch) {
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
count = deleteInTransaction(uri, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
onEndTransaction();
} else {
count = deleteInTransaction(uri, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
}
return count;
}
父類回調deleteInTransaction(uri, selection, selectionArgs);刪除聯系人操作在這里進行。
//該方法對uri進行匹配來執行相應的刪除操作,並且是在事務中完成的,,比如
//content://com.android.contacts/contacts
//content://com.android.contacts/contacts/#
// .......................................................省略
@Override
protected int deleteInTransaction(Uri uri, String selection, String[] selectionArgs) {
.......................................................
.......................................................
//我們可以在uri中的authority部分可帶可選的參數ContactsContract.CALLER_IS_SYNCADAPTER
//比如uri字元串可以寫成content://com.android.contacts?ContactsContract.CALLER_IS_SYNCADAPTER=true
// ContactsContract.CALLER_IS_SYNCADAPTER默認是false的,他告訴同步適配器如何執行刪除操作。
//如果設置為true,則delete的時候直接刪除聯系人,否則,默認delete時是不會立即刪除RawContacts中的數據的,
//只是把RawContacts.DELETED標志位設置為1,從它的aggregate contact中移除該raw contact,即顯示聯系人時不顯示它的內容
//同步聯系人時,刪除伺服器上的raw contact,最終刪除手機上已
//標記為DELETED為1的raw contacts
final boolean callerIsSyncAdapter = readBooleanQueryParameter(uri, ContactsContract.CALLER_IS_SYNCADAPTER, false);
final int match = sUriMatcher.match(uri);
switch (match) {
.......................................................
.......................................................
.......................................................
case CONTACTS: {//uri為content://com.android.contacts/contacts,目錄(dir)類型
// TODO
return 0;
}
case CONTACTS_ID: {//刪除某一個聯系人,uri指定了ContactsContract.Contacts中的欄位contact_id,Item類型
long contactId = ContentUris.parseId(uri);//得到該給定聯系人數據集的id
return deleteContact(contactId);
}
.......................................................
.......................................................
.......................................................
case RAW_CONTACTS: {
int numDeletes = 0;
Cursor c = mDb.query(Tables.RAW_CONTACTS, new String[]{RawContacts._ID},
appendAccountToSelection(uri, selection), selectionArgs, null, null, null);
try {
while (c.moveToNext()) {
final long rawContactId = c.getLong(0);
numDeletes += deleteRawContact(rawContactId, callerIsSyncAdapter);
}
} finally {
c.close();
}
return numDeletes;
}
case RAW_CONTACTS_ID: {
final long rawContactId = ContentUris.parseId(uri);
return deleteRawContact(rawContactId, callerIsSyncAdapter);
}
case DATA: {
mSyncToNetwork |= !callerIsSyncAdapter;
return deleteData(appendAccountToSelection(uri, selection), selectionArgs,
callerIsSyncAdapter);
}
case DATA_ID:
case PHONES_ID:
case EMAILS_ID:
case POSTALS_ID: {
long dataId = ContentUris.parseId(uri);
mSyncToNetwork |= !callerIsSyncAdapter;
return deleteData(Data._ID + "=" + dataId, null, callerIsSyncAdapter);
}
.......................................................
.......................................................
.......................................................
}
}
public int deleteRawContact(long rawContactId, boolean callerIsSyncAdapter) {
if (callerIsSyncAdapter) {
mDb.delete(Tables.PRESENCE, PresenceColumns.RAW_CONTACT_ID + "=" + rawContactId, null);
//直接刪除數據
return mDb.delete(Tables.RAW_CONTACTS, RawContacts._ID + "=" + rawContactId, null);
} else {
//從他關聯的aggregate contact移除該數據
mDbHelper.removeContactIfSingleton(rawContactId);
//標記為已刪除,但不是立即刪除數據
return markRawContactAsDeleted(rawContactId);
}
}
綜上,我們要刪除聯系人可以這樣做:
1)刪除單個聯系人:
CR.delete(ContactsContract.RawContacts.CONTENT_URI,ContactsContract.RawContacts_id + "=" + delRawId);
2)刪除全部聯系人:
getContentResolver().delete(Uri.parse(ContactsContract.RawContacts.CONTENT_URI.toString() +"?" + ContactsContract.CALLER_IS_SYNCADAPTER+"=true"), ContactsContract.RawContacts._ID + ">0", null));
數據索引從1開始,所以只要id>0就可以全部刪除raw contact記錄,上面的刪除操作是立即進行的,因為我們設置了true.
㈢ android 打開編輯聯系人界面
這些睜鬧戚action 可以在谷歌官網的 開發者文檔看到的,因為現在不太容易訪問谷歌的悉陵網站了,所彎嘩以你可以網路一下這些action,有好心的開發者會整理出來的!
㈣ android 怎麼調用聯系人列表,並將選擇的聯系人號碼顯示在文本框里
跳轉到聯系人:
Intent i = new Intent(Intent.ACTION_PICK);
i.setType("vnd.android.cursor.dir/phone");
startActivityForResult(i, 0);
獲取選擇的號碼:
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0:
if (data == null) {
return;
}
Uri uri = data.getData();
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
String number = cursor.getString(cursor.getColumnIndexOrThrow(Phones.NUMBER));
Log.d(TAG, "number" + number);
mContactText.setText(number);
mContactText.setSelection(number.length());
break;
default:
break;
}
}