almost 11 years ago
We can get a contact information for any contact from contact list of an Android Device easily. For this follow the steps below:
Write the permission to read Contact's data into your AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
Write the below code within your activity from where you want to perform action.
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(contactPickerIntent, 1001);
Also in your Activity, write the below code inside the onActivityResult method to listen for the result of step 2.
if(resultCode==RESULT_OK && requestCode==1001) { String ContactInfo = null; Uri uriOfPhoneNumberRecord = data.getData(); String idOfPhoneRecord = uriOfPhoneNumberRecord.getLastPathSegment(); Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?", new String[]{idOfPhoneRecord}, null); if(cursor != null) { if(cursor.getCount() > 0) { cursor.moveToFirst(); String formattedPhoneNumber = cursor.getString( cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA) ); String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); StringBuffer s=new StringBuffer(formattedPhoneNumber); for(int j=0;j<s.length();j++){ if(s.charAt(j)=='-') { s.replace(j, j+1, ""); } } ContactInfo = "Contact:\n".concat(contactName.concat("\n"+s.toString())); Log.d("Varta", String.format("The selected phone number is: %s", ContactInfo)); } cursor.close(); } }
Please feel free to share the experiences you had while getting contact information from contact list in your code as this will help other people who read the post.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)