i'm coding some little functionalities for an sms application.
My trouble is here : i can go in contact list, choose a name, then click and the name + the phone number will go in the edit Text.
But when i want to take another contact, only the name in the edit text is changing, not the phone number !Some people said me i have an error in my request Uri . here's a part of my code :
- Code: Select all
// Bouton contact
public void onClick(View v) {
switch (v.getId()) {
case R.id.boutonContact:
// on crée un nouvel intent qui appelera une activité secondaire et
// qui aura pour action de selectionner une donnée
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
// un setType pour indiquer que l'objet intent doit retourner un
// type Contact
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
// lancement de l'activité et attente d'un retour de type
// PICK_CONTACT
startActivityForResult(intent, PICK_CONTACT);
break;
}
}
// permet de recuperer ce que startActivityForResult à envoyé
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Uri phoneUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] PHONES_PROJECTION = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER };
String PHONE_SELECTION = null;
if (requestCode == PICK_CONTACT) {
// creation objet cursor pour analyser chaque enregistrements
Cursor phones = managedQuery(phoneUri, PHONES_PROJECTION,
PHONE_SELECTION, null,
ContactsContract.CommonDataKinds.Phone.IS_PRIMARY
);
phones.moveToFirst();
Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
cursor.moveToNext();
// bouger le curseur à la position suivante
// cursor.moveToNext();
if (resultCode == RESULT_OK) {
// retourne l'index de la colonne et jette un exception s'il
// elle n'existe pas et retourne l'index de cette colonen en
// string
String numContact =
phones.getString(phones
.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
String name = cursor.getString(cursor
.getColumnIndexOrThrow(
ContactsContract.Contacts.DISPLAY_NAME));
// recuperer valeur de name dans l'edit text
((TextView) findViewById(R.id.numero)).setText(String
.valueOf(name+"("+
numContact+")"));
} else {
Intent retour = new Intent(SmsActivity.this,
ContactsContract.Contacts.class);
startActivity(retour);
Log.e("RESULT_OK", "erreur");
Toast.makeText(this, "opération annulée", Toast.LENGTH_SHORT)
.show();
}
}
}
Problem n°2:
I dont know why but i cant start writing a message at the top left corner. Its starting in the middle ! why ? screenshot :
http://images4.hiboox.com/images/1912/0 ... c09d6b.png
Sorry for mistakes, i'm not english
Can you help ? thanks you

