Posts

Showing posts from November, 2014

Open Contacts using Intent and get Contact in onActivityResult()

Image
Here, I am launching contacts from my app using a button click. I am opening contacts which have phone numbers. Here we are launching contacts using startActivityForResult, so while returning back to the app, app will get the selected contact info in onActivityResult() of Activity class.

The code snippet is as,

((Button) findViewById(R.id.btn_openContacts)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI); i.setType(Phone.CONTENT_TYPE); startActivityForResult(i, PICK_CONTACT); } }); onActivityResult() will be look like this,
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.i(TAG, "onActivityResult()"); …