Hello I'm facing a basic problem but i didn't find any tutorial in
order to help me...

I'm writing an application with sort of backup contact options. I want
that my applications works for android phones since 1.5 to 2.2

So i write a two implementation of ContactApi, one for 1.5, 1.6 and an
other for new api version.

Here is the list of problem I'm facing with.

With new api, nothing. All works fine, backing up contacts works well.
But with older api I'm not able to backing up some datas :
 * Email Datas (able to read, but not able to save)
 * IM datas (able to read, but not able to save)
 * Notes (able to read the first note, if many notes, I lost datas,
same things for backup)


Here is the code I'm using :

=======EMAIL=======
private ArrayList<Email> getEmailAddresses(String id) {
                ArrayList<Email> emails = new ArrayList<Email>();

                Cursor emailCur =
this.contentResolver.query(Contacts.ContactMethods.CONTENT_EMAIL_URI,
null, Contacts.ContactMethods.PERSON_ID + " = ?", new String[] { id },
null);
                Email email = null;
                while (emailCur.moveToNext()) {
                        // This would allow you get several email addresses
                        email = new Email();
        
email.setData(emailCur.getString(emailCur.getColumnIndex(Contacts.ContactMethods.DATA)));
        
email.setType(emailCur.getInt(emailCur.getColumnIndex(Contacts.ContactMethods.TYPE)));
        
email.setLabel(emailCur.getString(emailCur.getColumnIndex(Contacts.PeopleColumns.NAME)));
                        emails.add(email);
                }
                emailCur.close();
                return emails;
        }

private void saveEmailAddresses(ContentUris contactUri, List<Email>
emailList, String id) {
                if (emailList != null && emailList.size() > 0) {
                        ContentValues values = null;
                        ContentValues[] valueArray = new 
ContentValues[emailList.size()];
                        int i = 0;
                        for (Email email : emailList) {
                                values = new ContentValues();
                                values.put(Contacts.ContactMethods.PERSON_ID, 
id); //
                                values.put(Contacts.ContactMethods.KIND, 
Contacts.KIND_EMAIL); //
                                values.put(Contacts.ContactMethods.DATA, 
email.getData()); //
                                values.put(Contacts.ContactMethods.TYPE, 
email.getType()); //
                                values.put(Contacts.PeopleColumns.NAME, 
email.getLabel()); //

                                valueArray[i] = values;
                                i++;
                        }

        
contentResolver.bulkInsert(Contacts.ContactMethods.CONTENT_EMAIL_URI,
valueArray);

                }
        }


======== IM adress=============

private ArrayList<IM> getIM(Cursor cur, String id) {
                ArrayList<IM> imList = new ArrayList<IM>();
                String where = Contacts.ContactMethods.PERSON_ID + " = ? AND " +
Contacts.ContactMethods.KIND + " = ?";
                String[] whereParameters = new String[] { id,
String.valueOf(Contacts.KIND_IM) };

                Cursor imCur =
this.contentResolver.query(Contacts.ContactMethods.CONTENT_URI, null,
where, whereParameters, null);
                IM im = null;
                while (imCur.moveToNext()) {
                        try {
                                String imName =
imCur.getString(imCur.getColumnIndex(Contacts.ContactMethodsColumns.DATA));
                                        im = new IM();
                                        im.setName(imName);
        
im.setType(imCur.getInt(imCur.getColumnIndex(Contacts.ContactMethodsColumns.TYPE)));
        
im.setProtocol(cur.getString(imCur.getColumnIndex(Contacts.ContactMethods.AUX_DATA)));
                                        imList.add(im);
                        } catch (Exception e) {
                                Log.e(where, "Error im : ", e);
                        }
                }
                imCur.close();
                return imList;
        }

        private void saveIM(List<IM> imList, String id) {
                if (imList != null && imList.size() > 0) {
                        ContentValues values = null;
                        ContentValues[] valueArray = new 
ContentValues[imList.size()];
                        int i = 0;
                        for (IM im : imList) {

                                values = new ContentValues();
                                values.put(Contacts.ContactMethods.PERSON_ID, 
id); //
                                values.put(Contacts.ContactMethods.KIND, 
Contacts.KIND_IM); //
                                values.put(Contacts.ContactMethodsColumns.DATA, 
im.getName()); //
                                values.put(Contacts.ContactMethods.AUX_DATA,
ContactMethods.encodeCustomImProtocol(im.getProtocol())); //
                                values.put(Contacts.ContactMethodsColumns.TYPE, 
im.getType()); //

                                valueArray[i] = values;
                                i++;

                        }
                        
contentResolver.bulkInsert(Contacts.ContactMethods.CONTENT_URI,
valueArray);

                }
        }

==========Notes =======

I have no idea how to get all notes ?




Can someone help me with this ?

best regards

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to