1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| findViewById(R.id.buttonContact).setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
String[] info = null;
int y=0;
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
for (int i = 0; i < phones.getColumnCount(); i++)
{
try
{
Log.i(phones.getColumnName(i) + "", phones.getString(i));
}
catch (Exception e) {
e.printStackTrace();
}
}
String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
info[y] = phoneNumber;
try
{
info[y] = phoneNumber;
}
catch (Exception e) {
e.printStackTrace();
}
y++;
}
phones.close();
AlertDialog.Builder ad = new AlertDialog.Builder(getApplicationContext());
ad.setTitle("Contact");
ad.setItems(info, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Mettre le numéro dans une textarea
}
});
ad.show();
}
}); |
Partager