I've found an elegant solution after all:
My main activity launches an intermediate, invisible activity that has android:theme="@android:style/Theme.NoDisplay"
This intermediate activity calls the contact picker in its onCreate
Intent phoneContactIntent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
// Show user only contacts w/ phone numbers
phoneContactIntent.setType(Phone.CONTENT_TYPE);
startActivityForResult(phoneContactIntent, CHOOSE_CONTACT_TO_CALL);
Then, in onActivityResult
, it creates a new intent for the main application, with the data that the contact picker returned.
switch (requestCode) {
case (CHOOSE_CONTACT_TO_CALL):
if (resultCode == Activity.RESULT_OK) {
Intent resultIntent = new Intent(this, Home.class);
resultIntent.putExtras(data);
Uri contactData = data.getData();
if (contactData != null)
{
resultIntent.setData(contactData);
}
startActivity(resultIntent);
}
}
finish();
and in my Home class, in onCreate
I call getIntent()
and inspect the data in the intent that launched the main activity.