dubte accés dades contacts provider

0 views
Skip to first unread message

Jordi Hz

unread,
Jan 15, 2015, 6:24:52 AM1/15/15
to CatD...@googlegroups.com
Bon dia,

Necessito accedir als contactes del dispositiu, concretament al nom, telefon i email si n'hi ha. Faig servir la URI Phone.CONTENT_URI i d'aquí trec d'un contacte concret
el Nom i el telèfon, però no el email. Crec que la culpa és de la URI, n'he de fer servir un altre? O dues alhora? per accedir a diferent informació en diferents URI's?

Sabeu quina és la millor manera de fer-ho?


Merci,

Ara el meu codi està així:

/*CONDICIONS*/
String[] mProjection = new String[]
           
{
               
Phone.DISPLAY_NAME,
               
Phone.NUMBER
       
           
};
       
       
String selection =  Phone.DISPLAY_NAME + " LIKE '" + sUser + "'";


       
// Retrieves the profile from the Contacts Provider
       
Cursor mProfileCursor =
                getContentResolver
().query(
                       
Phone.CONTENT_URI,
                        mProjection
,
                        selection
,
                       
null,
                       
null);



.....

/*i després això per accedir a la INFO */

if (mProfileCursor.moveToFirst()) {
           
String calName, numTel;
           
int numc = mProfileCursor.getCount();
           
int l_nameCol = mProfileCursor.getColumnIndex(mProjection[0]);
           
int l_numTel = mProfileCursor.getColumnIndex(mProjection[1]);
           
do {
                calName
= mProfileCursor.getString(l_nameCol);
                numTel
= mProfileCursor.getString(l_numTel);
               
if (calName.equals(sUser)) {
                    txtNomContacte
.setText("Nom = " + calName);
                    txtTelefon
.setText(numTel);
                   
               
}
           
}while (mProfileCursor.moveToNext());
           
       
}else {
            txtNomContacte
.setText("No hi ha contactes");
       
}


Sergi Martínez

unread,
Jan 15, 2015, 6:47:47 AM1/15/15
to CatD...@googlegroups.com
T'ho dic de memoria, així que potser em colo. Si vols el mail l'has d'afegir al projection i aleshores et retornarà n registres per contacte, un per cada mail i un per cada telefon.



--
You received this message because you are subscribed to the Google Groups "Catalonia Android Community Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to CatDroid+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages