나는 안드로이드 앱을 만들고 있습니다. 그룹에서 연락처를 삭제하지 않으려면 그룹에서 삭제하고 싶습니다. 그룹 ID와 연락처 ID가 있습니다. 누구든지 알려주십시오. 나를 쿼리 할 같은 것을 구현하고 싶습니다. contact_id = 1 from group_id = 2에서android에서 특정 그룹의 연락처 삭제하기
0
A
답변
1
연락처는 ContactsContract.CommonDataKinds.GroupMembership 레코드가있는 그룹에 연결됩니다. 당신은 그룹에서 연락처를 삭제하려면이 같은 것을 사용할 수 있습니다
private void deleteContactFromGroup(long contactId, long groupId)
{
ContentResolver cr = getContentResolver();
String where = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "=" + groupId + " AND "
+ ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID + "=?" + " AND "
+ ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + "='"
+ ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "'";
for (Long id : getRawContactIdsForContact(contactId))
{
try
{
cr.delete(ContactsContract.Data.CONTENT_URI, where,
new String[] { String.valueOf(id) });
} catch (Exception e)
{
e.printStackTrace();
}
}
}
private HashSet<Long> getRawContactIdsForContact(long contactId)
{
HashSet<Long> ids = new HashSet<Long>();
Cursor cursor = getContentResolver().query(RawContacts.CONTENT_URI,
new String[]{RawContacts._ID},
RawContacts.CONTACT_ID + "=?",
new String[]{String.valueOf(contactId)}, null);
if (cursor != null && cursor.moveToFirst())
{
do
{
ids.add(cursor.getLong(0));
} while (cursor.moveToNext());
cursor.close();
}
return ids;
}
삭제 수행 할 때, 당신은 RAW_CONTACT_ID 대신 CONTACT_ID를 지정해야합니다. 따라서 특정 연락처에 대해 모든 원시 컨택 ID를 쿼리해야합니다.
계정 데이터를 고려해야 할 수도 있습니다. 그런 일에 접촉 ID에 대한 쿼리 경우의 변경 :
Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType).build();
Cursor cursor = getContentResolver().query(rawContactUri,
new String[] { RawContacts._ID }, RawContacts.CONTACT_ID + "=?",
new String[] { String.valueOf(contactId) }, null);
0
public static Uri addContactToGroup(String rawContactId,String groupId)
{
try
{
ContentValues values = new ContentValues();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(GroupMembership.GROUP_ROW_ID, groupId);
values.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE);
return getContentResolver.insert(Data.CONTENT_URI, values);
}
catch (Exception e)
{}
return Uri.EMPTY;
}
// ------------------------- ----------
public static int removeContactFromGroup(String contactId,String groupId)
{
try
{
String where = Data.CONTACT_ID + " = ? AND " + Data.MIMETYPE + " = ? AND " + GroupMembership.GROUP_ROW_ID + " = ?";
String[] args = {contactId, GroupMembership.CONTENT_ITEM_TYPE, groupId};
return getContentResolver.delete(Data.CONTENT_URI, where, args);
}
catch (Exception e)
{}
return 0;
}
관련 문제
- 1. Android에서 그룹의 특정 연락처를 선택하십시오.
- 2. 그룹의 ID로 특정 그룹의 연락처 추가
- 3. 그룹의 모든 연락처 삭제
- 4. android에서 이메일을 원격으로 삭제하기
- 5. 연락처 그룹의 회원을 어떻게 얻습니까?
- 6. gdata는 특정 그룹의 연락처를 가져옵니다.
- 7. 특정 그룹에 속하는 연락처 목록을 얻으십시오
- 8. Google 연락처 android에서 api
- 9. Android에서 여러 연락처 선택
- 10. Android에서 연락처 관리
- 11. Android에서 알림과 연락처 저장
- 12. 연락처 Android에서 업데이트
- 13. android에서 연락처 읽기
- 14. Android에서 STARRED로 연락처 번호 변경
- 15. 연락처 그룹의 계정 속성을 찾는 중입니까?
- 16. Gmail에서 그룹의 모든 연락처 가져 오기
- 17. 특정 UNIX 그룹의 .htaccess
- 18. 특정 그룹의 사용자 목록보기
- 19. 특정 그룹의 전화 번호를 얻는 방법
- 20. android에서 연락처 변경 추적 문제
- 21. Android에서 연락처 기록을 조회하는 방법
- 22. android에서 연락처 저장 및 검색
- 23. android에서 연락처 사진 가져 오기
- 24. android의 특정 연락처 삭제
- 25. 특정 컴퓨터에있는 그룹의 사용자 구성원?
- 26. Android에서 연락처 애플리케이션의 소스 코드를 수정하십시오.
- 27. mysql을 사용하여 특정 조건에서 행 삭제하기
- 28. 특정 행만 유지하고 C에서 나머지 부분 삭제하기 #
- 29. 특정 RawContact 콘텐츠 디렉토리 항목 삭제하기
- 30. 그리드 Tkinter의 특정 행/열 삭제하기