Hello,
I have reviewed other post in in the topic , but i have’t found one which address to the following cenario.
i dont undestand why i cant execute the following code ?
instead of getting the id and name from the phone’s contacts , i was thinking to get the name and number
but the app crashed.
private String mPhoneNumber
//
private String getSuspectNamer(Intent data){
Uri contactUri = data.getData();
String[] queryFields = new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.Contacts.DISPLAY_NAME};
Cursor c = getActivity().getContentResolver()
.query(contactUri, queryFields, null, null, null);
try{
if (c.getCount() ==0){
return null;
}
//Pull out the first column of the first row of data - that is your suspet's name
c.moveToFirst();
mPhoneNumber= c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
return c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}finally {
c.close();
}
}