Help us to see. I do a query grouping contacts, how are false Oh
/ / Method is to check all contacts
grouped by the group id/ / The idea is by grouping id check out the data table of raw_contact_id
/ / To query a contact name and phone number
by raw_contact_id/ / Self is the context id is the id
contact group
Cursor cursor = self
. GetContentResolver (). Query (ContactsContract.Data.CONTENT_URI,
new String [] {ContactsContract.Data.RAW_CONTACT_ID},
ContactsContract.Data.MIMETYPE
+ "= '"
+ ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
+ "'" + "And" + ContactsContract.CommonDataKinds.GroupMembership._ID
+ "=?"
, New String [] {String.valueOf (id)}, null);
/ / Print out for false So now I still can not understand
Log.e (TAG, "query that groups of contacts cursor ********************:" + cursor.moveToFirst ());
Under the guidance we have given, thank you<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
I want to be android address book demo.
The main function with: the operating system address book contacts. This is relatively simple, the URL can get to, I can achieve.
But: I want to get the contact group, there is no thinking to do. android emulator, there is no grouping this option, only the collection, but there is a real machine grouping this feature.
So how to get the phone address book grouping set it? We talk about the idea of it!
The main features include: You can get the demo in the phone book in the grouping, grouping modify the name, you can add groups, delete groups, add team members, remove group members!
Thank you! I found a lot of information in Baidu google years, still confused. Later, to study the android contacts database, we help under the guidance oh
Reply:
Done!
Contact method outid / / query packet is a packet id
public ArrayList> getContactsByGroupId (int outid) {
Log.e (TAG, "the group began inquiries contact ******************** id:" + outid);
ArrayList> mymaplist = new ArrayList > ();
/ / We went to check RAW_CONTACT_ID ideas through group id, go through RAW_CONTACT_ID inquiries contact
/ / Get the data you want to query a table Data.RAW_CONTACT_ID field
String [] RAW_PROJECTION = new String [] {ContactsContract.Data.RAW_CONTACT_ID,};
String RAW_CONTACTS_WHERE = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID
+ "=?"
+ "And"
+ ContactsContract.Data.MIMETYPE
+ "="
+ "'"
+ ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
+ "'";
/ / By id outid grouping; queries get RAW_CONTACT_ID
Cursor cursor = myContext.getContentResolver (). Query (
ContactsContract.Data.CONTENT_URI, RAW_PROJECTION,
RAW_CONTACTS_WHERE, new String [] {"" + outid}, "data1 asc");
while (cursor.moveToNext ()) {
HashMapmap = new HashMap ();
/ / RAW_CONTACT_ID
int contactId = cursor.getInt (cursor
. GetColumnIndex ("raw_contact_id"));
Log.e (TAG, "check the group contact raw_contact_id ****************:" + contactId);
String [] RAW_PROJECTION02 = new String [] {ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,};
String RAW_CONTACTS_WHERE02 = ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID
+ "=?"
+ "And"
+ ContactsContract.Data.MIMETYPE
+ "="
+ "'"
+ ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
+ "'";
/ / Get the user's name
by value raw_contact_idCursor cursor01 = myContext.getContentResolver (). Query (
ContactsContract.Data.CONTENT_URI, RAW_PROJECTION02,
RAW_CONTACTS_WHERE02, new String [] {"" + contactId},
"Data1 asc");
String contacts_name = null;
while (cursor01.moveToNext ()) {
contacts_name = cursor01.getString (cursor01
. GetColumnIndex ("data1"));
Log.e (TAG, "Contact Name:" + contacts_name);
}
map.put (COLUMN_NAME, contacts_name);
String [] RAW_PROJECTION03 = new String [] {ContactsContract.CommonDataKinds.Phone.NUMBER,};
String RAW_CONTACTS_WHERE03 = ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ "=?"
+ "And"
+ ContactsContract.Data.MIMETYPE
+ "="
+ "'"
+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
+ "'";
/ / When there are multiple numbers/ / String num_str = cursor
/ /. GetString (cursor
. / / GetColumnIndex (ContactsContract.Contacts.HAS_PHONE_NUMBER));
/ / Int num = Integer.valueOf (num_str);
/ / If (num> 0) {
/ / Get the phone number
by raw_contact_idCursor cursor02 = myContext.getContentResolver (). Query (
ContactsContract.Data.CONTENT_URI, RAW_PROJECTION03,
RAW_CONTACTS_WHERE03, new String [] {"" + contactId},
"Data1 asc");
String phonenum = null;
while (cursor02.moveToNext ()) {
phonenum = cursor02.getString (cursor02.getColumnIndex ("data1"));
/ / Map.put ("phonekey", phonenum);
Log.e (TAG, "Contact Phone Number:" + phonenum);
}
map.put (COLUMN_NUMBER, phonenum);
/ /}
mymaplist.add (map);
}
Log.e (TAG, "the end of the restructuring contact query returns a collection of contacts ********************" + mymaplist.size ());
return mymaplist;
}
Reply:
There are: Code chaotic, we hope to optimize! Thank you!
/ / Query no grouping contacts
public ArrayList> getContactsByNoGroup () {
Log.e (TAG, "query does not start grouping contacts ********************");
ArrayList> mymaplist = new ArrayList > ();
/ / We went to check RAW_CONTACT_ID ideas through group id, go through RAW_CONTACT_ID inquiries contact
/ / Query ungrouped contacts filter
String RAW_CONTACTS_IN_NO_GROUP_SELECTION = "1 = 1) and"
+ Data.RAW_CONTACT_ID + "not in (select"
+ Data.RAW_CONTACT_ID + "from view_data_restricted where"
+ Data.MIMETYPE + "= '" + GroupMembership.CONTENT_ITEM_TYPE
+ "') Group by (" + Data.RAW_CONTACT_ID;
Cursor cursor = myContext.getContentResolver (). Query (Data.CONTENT_URI,
null, RAW_CONTACTS_IN_NO_GROUP_SELECTION, null, null);
Log.e (TAG,
"Query the group contact cursorgetCount ********************:"
+ Cursor.getCount ());
while (cursor.moveToNext ()) {
HashMapmap = new HashMap ();
/ / RAW_CONTACT_ID
int contactId = cursor.getInt (cursor
. GetColumnIndex ("raw_contact_id"));
Log.e (TAG, "query that groups of contacts cursor *** contact id ****************:" + contactId);
String [] RAW_PROJECTION02 = new String [] {ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,};
String RAW_CONTACTS_WHERE02 = ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID
+ "=?"
+ "And"
+ ContactsContract.Data.MIMETYPE
+ "="
+ "'"
+ ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
+ "'";
Cursor cursor01 = myContext.getContentResolver (). Query (
ContactsContract.Data.CONTENT_URI, RAW_PROJECTION02,
RAW_CONTACTS_WHERE02, new String [] {"" + contactId},
"Data1 asc");
String contacts_name = null;
while (cursor01.moveToNext ()) {
contacts_name = cursor01.getString (cursor01
. GetColumnIndex ("data1"));
Log.e (TAG, "Contact Name:" + contacts_name);
}
map.put (COLUMN_NAME, contacts_name);
/ / When there are multiple numbers
String [] RAW_PROJECTION03 = new String [] {ContactsContract.CommonDataKinds.Phone.NUMBER,};
String RAW_CONTACTS_WHERE03 = ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ "=?"
+ "And"
+ ContactsContract.Data.MIMETYPE
+ "="
+ "'"
+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
+ "'";
/ / String num_str = cursor
/ /. GetString (cursor
. / / GetColumnIndex (ContactsContract.Contacts.HAS_PHONE_NUMBER));
/ / Int num = Integer.valueOf (num_str);
/ / If (num> 0) {
Cursor cursor02 = myContext.getContentResolver (). Query (
ContactsContract.Data.CONTENT_URI, RAW_PROJECTION03,
RAW_CONTACTS_WHERE03, new String [] {"" + contactId},
"Data1 asc");
String phonenum = null;
while (cursor02.moveToNext ()) {
phonenum = cursor02.getString (cursor02.getColumnIndex ("data1"));
map.put ("phonekey", phonenum);
Log.e (TAG, "Contact Phone Number:" + phonenum);
}
map.put (COLUMN_NUMBER, phonenum);
/ /}
mymaplist.add (map);
}
Log.e (TAG, "the end of the inquiry are not grouped contacts, returns combined ********************" + mymaplist.size ());
return mymaplist;
}
Reply:
First under the roof, lz there is a problem, ah, you outid this grouping is coming from? He went to the area to see the database?
No comments:
Post a Comment