Contact Picker に問題があります。Phone.DISPLAY_NAME と Phone.NUMBER では機能しますが、Email.ADDRESS では機能しません。
public class CustomerForm extends Activity {
private final static int CONTACT_PICKER = 1;
private EditText txtMailContacto;
private EditText txtNombreContacto;
private EditText txtTelefono;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_form);
txtMailContacto = (EditText) findViewById(R.id.txtMailContacto);
txtTelefono = (EditText) findViewById(R.id.txtTelefono);
txtNombreContacto = (EditText) findViewById(R.id.txtNombreContacto);
}
public void pickContact(View v)
{
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// check whether the result is ok
if (resultCode == RESULT_OK) {
// Check for the request code, we might be usign multiple startActivityForReslut
switch (requestCode) {
case CONTACT_PICKER:
contactPicked(data);
break;
}
} else {
Log.e("MainActivity", "Failed to pick contact");
}
}
private void contactPicked(Intent data) {
Cursor cursor = null;
try {
String mail = null ;
String phoneNo = null ;
String name = null;
// getData() method will have the Content Uri of the selected contact
Uri uri = data.getData();
//Query the content uri
cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
// column index of the phone number
int phoneIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
// column index of the email
int mailIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS);
// column index of the contact name
int nameIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
mail = cursor.getString(mailIndex);
phoneNo = cursor.getString(phoneIndex);
name = cursor.getString(nameIndex);
// Set the value to the textviews
txtMailContacto.setText(mail);
txtTelefono.setText(phoneNo);
txtNombreContacto.setText(name);
} catch (Exception e) {
e.printStackTrace();
}
}
}
それで、私はそれらのフィールドを取得しようとしていますが、何が問題なのかわかりません。助けてくれてありがとう...