連絡先IDを使用して、Androidのネイティブ連絡先で名、名前、携帯電話番号、写真、メールアドレス、住所をプログラムで編集する方法。私を助けてください。前もって感謝します。
質問する
543 次
1 に答える
0
ボタンをクリックして、次の手順を実行します。
Intent in = new Intent(Intent.ACTION_INSERT_OR_EDIT);
in.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
startActivityForResult(in,EDIT_CONTACT);
そしてonActivityResult関数でこれを行います:
ケースEDIT_CONTACT:
if (resultCode == RESULT_OK) {
Uri contactData = data.getData();
Cursor cur = managedQuery(contactData, null, null, null, null);
ContentResolver contect_resolver = getContentResolver();
if (cur.moveToFirst()) {
String id = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String name = "";
String no = "";
String key = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts.LOOKUP_KEY));
String where = ContactsContract.Data.DISPLAY_NAME + " = ? AND " +
ContactsContract.Data.MIMETYPE + " = ? AND " +
String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE) + " = ? ";
String[] params = new String[] {name,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_HOME)};
Cursor phoneCur = contect_resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
if (phoneCur.moveToFirst()) {
name = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
no = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
key = phoneCur.getString(phoneCur.getColumnIndexOrThrow(ContactsContract.Contacts.LOOKUP_KEY));
System.out.println("EDITIDDDDDDDDDD"+name);
System.out.println("EDITIDDDDDDDDDD"+no);
System.out.println("EDITIDDDDDDDDDD"+key);
/*ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
if ( (null == phoneCur) ) {
// createContact(name, phone);
} else {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(where, params)
.withValue(ContactsContract.CommonDataKinds.Phone.DATA, no)
.build());
}
phoneCur.close();
try {
cr.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
id = null;
name = null;
no = null;
phoneCur = null;
key = null;
contect_resolver = null;
cur = null;
}
}
}
break;
于 2012-12-20T09:24:29.020 に答える