Q:

android how to tag phone number of a contact programmatically

i did a lot of research but couldn't find anything to help;
my problem is: i need to create an application  where the user can select some of the contacts on his phone to be added to this application where he/she can later communicate with them via sms in a special template. but the user need to select only one phone number to be active to this user on this application. this choice must be caved for later logons.
i was able to retrieve contacts and their phone numbers using lookupkey (which will be saved in my application as a reference for preselected users), but i couldn't figure out how to tag the needed phone number, i was thinking of adding a flag to the phone number but i dont know how, i dont know if this is the right way to do it, i thought of setting the selected phone number as primary then query t when needed... or simply save the phone number id (but i am not sure if saving the id is safe in case user changed the phone numer)...
thx for any help...

A:

After a long period of trial and error I found the solution to my problem. I will be using the contacts lookup key to store the contact and the phone id to store the phone number...as follows:
String selection =  ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY + " = '" + lookupkey+ "' and "+Phone._ID+"='"+phoneid+"'";
        String[] projection =new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER};
         Cursor managedCursor = getContentResolver()
                .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                 projection, selection, null,  Phone.DISPLAY_NAME + " ASC");

