0
All right, guys ? I have a problem in the development of an app, because when I call his registration screen before I want to take the name and phone of the selected contact and send to the Activity Edit, but I can’t recover the name and neither at the same time, just the number, would you please help me get them both back at the same time? follows the code I use to recover the number and that is currently working:
public void SelecionarContato(){
Intent contatos = new Intent(Intent.ACTION_PICK); //CHAMANDO UMA ACTIVITY COM A CONSTANTE DE ESCOLHER UM DADO A SER RETORNADO
contatos.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); //SELECIONANDO O CONTEUDO UTILIZANDO A CONTACTS PROVIDER
//VALIDANDO
if (contatos.resolveActivity(getPackageManager()) != null){
//CHAMO OS CONTATOS
startActivityForResult(contatos, REQUEST_SELECT_PHONE_NUMBER);
}
}
//TRATANDO O RESULTADO DO RETORNO DOS CONTATOS
protected void onActivityResult(int RequestCode, int ResultCode, Intent Data){
if (RequestCode == REQUEST_SELECT_PHONE_NUMBER && ResultCode == RESULT_OK){ //O ULTIMO PARAMETRO É PARA CASO O USUARIO CANCELE
//Pegar a URI e a Query do contactProvider e o numero do telefone
Uri contatoUri = Data.getData();
String[] projecao = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor cursor = getContentResolver().query(contatoUri, projecao, null, null, null);
//SE O CURSOR RETORNAR UM VALOR VALIDO ENTÃO PEGA O NUMERO
if (cursor != null && cursor.moveToFirst()){
int indexNumero = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String number = cursor.getString(indexNumero);
//ação do que recebe o numero do contato e envia para a activity
telefone.setText(number);
telefone.setEnabled(false);
}
It would be better to post what you tried to do, because in theory there is no reason not to be able to get the 2 data at the same time, since it is a Contentprovider that returns a Cursor.
– Márcio Oliveira
In your projected array, you passed the number and contact?
– Márcio Oliveira
I tried several ways but I am already without ideas of how to do, the last attempt was this, trying to recover it inside the projection array along with the name, remembering that the code I sent above works perfectly to bring the number:
– Eduardo Rafael Moraes