You can read phone contacts using Content Provider. With the help of this content provider we can communicate with the contacts app and query the URIs and columns to get contact information and it will return as contact name, all contact numbers, all email addresses, company name, etc.
Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process. A content provider is only required if you need to share data between multiple applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don’t need to share data amongest multiple applications you can use a database directly via SQLiteDatabase
.
When you want to access data in a content provider, you use the ContentResolver
object in your application’s Context
to communicate with the provider as a client. The ContentResolver
object communicates with the provider object, an instance of a class that implements ContentProvider
. The provider object receives data requests from clients, performs the requested action, and returns the results.
In this tutorial, we are going to learn how to read contact details using content provider.
1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is MainActivity.java.
2. Now, to read contact details we have to give “READ_CONTACTS” this permission in our Manifest file.
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 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.phonecontact_demo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.READ_CONTACTS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.phonecontact_demo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
3. Create a xml layout naming activity_main.xml that contains one listview that will display the contact details.
1 2 3 4 5 6 7 8 9 10 11 12 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/contact_listview" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout> |
4. Now, create a new xml layout naming custom_view.xml for custom listview layout. Since we have to display contact details like name, number, email, image and other details so we are using custom view.
If you are new to custom list view then you can read here.
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 49 50 51 52 53 54 55 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" > <ImageView android:id="@+id/contactImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/contactName" android:layout_centerHorizontal="true" android:contentDescription="@string/image" android:padding="5dp" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/contactName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:lineSpacingExtra="3dp" android:padding="5dp" android:textColor="#000000" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/contactNumber" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/contactImage" android:lineSpacingExtra="3dp" android:padding="5dp" android:textSize="15sp" /> <TextView android:id="@+id/contactEmail" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/contactNumber" android:lineSpacingExtra="3dp" android:padding="5dp" android:textSize="15sp" /> <TextView android:id="@+id/contactOtherDetails" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/contactEmail" android:lineSpacingExtra="3dp" android:padding="5dp" android:textSize="15sp" /> </RelativeLayout> |
5. Now, create a new java class naming Contact_Model.java for getter and setter for contact details.
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 |
package com.phonecontact_demo; public class Contact_Model { // Getter and setter for contacts private String contactId, contactName, contactNumber, contactEmail, contactPhoto, contactOtherDetails; public Contact_Model(String contactId, String contactName, String contactNumber, String contactEmail, String contactPhoto, String contactOtherDetails) { this.contactId = contactId; this.contactName = contactName; this.contactEmail = contactEmail; this.contactNumber = contactNumber; this.contactPhoto = contactPhoto; this.contactOtherDetails = contactOtherDetails; } public String getContactID() { return contactId; } public String getContactName() { return contactName; } public String getContactEmail() { return contactEmail; } public String getContactNumber() { return contactNumber; } public String getContactPhoto() { return contactPhoto; } public String getContactOtherDetails() { return contactOtherDetails; } } |
6. Now, create a custom adapter class naming Contact_Adapter.java for inflating a custom layout over listview.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
package com.phonecontact_demo; import java.util.ArrayList; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class Contact_Adapter extends BaseAdapter { private Context context; private ArrayList<Contact_Model> arrayList; public Contact_Adapter(Context context, ArrayList<Contact_Model> arrayList) { this.context = context; this.arrayList = arrayList; } @Override public int getCount() { return arrayList.size(); } @Override public Contact_Model getItem(int position) { return arrayList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); Contact_Model model = arrayList.get(position); ViewHodler holder; if (convertView == null) { convertView = inflater.inflate(R.layout.custom_view, parent, false); holder = new ViewHodler(); holder.contactImage = (ImageView) convertView .findViewById(R.id.contactImage); holder.contactName = (TextView) convertView .findViewById(R.id.contactName); holder.contactEmail = (TextView) convertView .findViewById(R.id.contactEmail); holder.contactNumber = (TextView) convertView .findViewById(R.id.contactNumber); holder.contactOtherDetails = (TextView) convertView .findViewById(R.id.contactOtherDetails); convertView.setTag(holder); } else { holder = (ViewHodler) convertView.getTag(); } // Set items to all view if (!model.getContactName().equals("") && model.getContactName() != null) { holder.contactName.setText(model.getContactName()); } else { holder.contactName.setText("No Name"); } if (!model.getContactEmail().equals("") && model.getContactEmail() != null) { holder.contactEmail.setText("EMAIL ID - n" + model.getContactEmail()); } else { holder.contactEmail.setText("EMAIL ID - n" + "No EmailId"); } if (!model.getContactNumber().equals("") && model.getContactNumber() != null) { holder.contactNumber.setText("CONTACT NUMBER - n" + model.getContactNumber()); } else { holder.contactNumber.setText("CONTACT NUMBER - n" + "No Contact Number"); } if (!model.getContactOtherDetails().equals("") && model.getContactOtherDetails() != null) { holder.contactOtherDetails.setText("OTHER DETAILS - n" + model.getContactOtherDetails()); } else { holder.contactOtherDetails.setText("OTHER DETAILS - n" + "Other details are empty"); } // Bitmap for imageview Bitmap image = null; if (!model.getContactPhoto().equals("") && model.getContactPhoto() != null) { image = BitmapFactory.decodeFile(model.getContactPhoto());// decode // the // image // into // bitmap if (image != null) holder.contactImage.setImageBitmap(image);// Set image if bitmap // is not null else { image = BitmapFactory.decodeResource(context.getResources(), R.drawable.androhub_logo);// if bitmap is null then set // default bitmap image to // contact image holder.contactImage.setImageBitmap(image); } } else { image = BitmapFactory.decodeResource(context.getResources(), R.drawable.androhub_logo); holder.contactImage.setImageBitmap(image); } return convertView; } // View holder to hold views private class ViewHodler { ImageView contactImage; TextView contactName, contactNumber, contactEmail, contactOtherDetails; } } |
7. To read contact details we have to know certain things mentioned below :
1 |
Uri uri = ContactsContract.Contacts.CONTENT_URI; |
1 2 |
Cursor contactsCursor = getContentResolver().query(uri, null, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC "); |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
private ArrayList<Contact_Model> readContacts() { ArrayList<Contact_Model> contactList = new ArrayList<Contact_Model>(); Uri uri = ContactsContract.Contacts.CONTENT_URI; // Contact URI Cursor contactsCursor = getContentResolver().query(uri, null, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC "); // Return // all // contacts // name // containing // in // URI // in // ascending // order // Move cursor at starting if (contactsCursor.moveToFirst()) { do { long contctId = contactsCursor.getLong(contactsCursor .getColumnIndex("_ID")); // Get contact ID Uri dataUri = ContactsContract.Data.CONTENT_URI; // URI to get // data of // contacts Cursor dataCursor = getContentResolver().query(dataUri, null, ContactsContract.Data.CONTACT_ID + " = " + contctId, null, null);// Retrun data cusror represntative to // contact ID // Strings to get all details String displayName = ""; String nickName = ""; String homePhone = ""; String mobilePhone = ""; String workPhone = ""; String photoPath = "" + R.drawable.ic_launcher; // Photo path byte[] photoByte = null;// Byte to get photo since it will come // in BLOB String homeEmail = ""; String workEmail = ""; String companyName = ""; String title = ""; // This strings stores all contact numbers, email and other // details like nick name, company etc. String contactNumbers = ""; String contactEmailAddresses = ""; String contactOtherDetails = ""; // Now start the cusrsor if (dataCursor.moveToFirst()) { displayName = dataCursor .getString(dataCursor .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));// get // the // contact // name do { if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE)) { nickName = dataCursor.getString(dataCursor .getColumnIndex("data1")); // Get Nick Name contactOtherDetails += "NickName : " + nickName + "n";// Add the nick name to string } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) { // In this get All contact numbers like home, // mobile, work, etc and add them to numbers string switch (dataCursor.getInt(dataCursor .getColumnIndex("data2"))) { case ContactsContract.CommonDataKinds.Phone.TYPE_HOME: homePhone = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactNumbers += "Home Phone : " + homePhone + "n"; break; case ContactsContract.CommonDataKinds.Phone.TYPE_WORK: workPhone = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactNumbers += "Work Phone : " + workPhone + "n"; break; case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE: mobilePhone = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactNumbers += "Mobile Phone : " + mobilePhone + "n"; break; } } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) { // In this get all Emails like home, work etc and // add them to email string switch (dataCursor.getInt(dataCursor .getColumnIndex("data2"))) { case ContactsContract.CommonDataKinds.Email.TYPE_HOME: homeEmail = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactEmailAddresses += "Home Email : " + homeEmail + "n"; break; case ContactsContract.CommonDataKinds.Email.TYPE_WORK: workEmail = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactEmailAddresses += "Work Email : " + workEmail + "n"; break; } } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)) { companyName = dataCursor.getString(dataCursor .getColumnIndex("data1"));// get company // name contactOtherDetails += "Coompany Name : " + companyName + "n"; title = dataCursor.getString(dataCursor .getColumnIndex("data4"));// get Company // title contactOtherDetails += "Title : " + title + "n"; } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)) { photoByte = dataCursor.getBlob(dataCursor .getColumnIndex("data15")); // get photo in // byte if (photoByte != null) { // Now make a cache folder in file manager to // make cache of contacts images and save them // in .png Bitmap bitmap = BitmapFactory.decodeByteArray( photoByte, 0, photoByte.length); File cacheDirectory = getBaseContext() .getCacheDir(); File tmp = new File(cacheDirectory.getPath() + "/_androhub" + contctId + ".png"); try { FileOutputStream fileOutputStream = new FileOutputStream( tmp); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } photoPath = tmp.getPath();// finally get the // saved path of // image } } } while (dataCursor.moveToNext()); // Now move to next // cursor contactList.add(new Contact_Model(Long.toString(contctId), displayName, contactNumbers, contactEmailAddresses, photoPath, contactOtherDetails));// Finally add // items to // array list } } while (contactsCursor.moveToNext()); } return contactList; } |
8. Finally open your MainActivty.java and add the following code. In this class we fetch contact details using AsyncTask and display over listview.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
package com.phonecontact_demo; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Random; import android.app.ProgressDialog; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.ContactsContract; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private static ListView contact_listview; private static ArrayList<Contact_Model> arrayList; private static Contact_Adapter adapter; private static ProgressDialog pd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); contact_listview = (ListView) findViewById(R.id.contact_listview); new LoadContacts().execute();// Execute the async task } // Async task to load contacts private class LoadContacts extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { arrayList = readContacts();// Get contacts array list from this // method return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); // If array list is not null and is contains value if (arrayList != null && arrayList.size() > 0) { // then set total contacts to subtitle getSupportActionBar().setSubtitle( arrayList.size() + " Contacts"); adapter = null; if (adapter == null) { adapter = new Contact_Adapter(MainActivity.this, arrayList); contact_listview.setAdapter(adapter);// set adapter } adapter.notifyDataSetChanged(); } else { // If adapter is null then show toast Toast.makeText(MainActivity.this, "There are no contacts.", Toast.LENGTH_LONG).show(); } // Hide dialog if showing if (pd.isShowing()) pd.dismiss(); } @Override protected void onPreExecute() { super.onPreExecute(); // Show Dialog pd = ProgressDialog.show(MainActivity.this, "Loading Contacts", "Please Wait..."); } } // Method that return all contact details in array format private ArrayList<Contact_Model> readContacts() { ArrayList<Contact_Model> contactList = new ArrayList<Contact_Model>(); Uri uri = ContactsContract.Contacts.CONTENT_URI; // Contact URI Cursor contactsCursor = getContentResolver().query(uri, null, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC "); // Return // all // contacts // name // containing // in // URI // in // ascending // order // Move cursor at starting if (contactsCursor.moveToFirst()) { do { long contctId = contactsCursor.getLong(contactsCursor .getColumnIndex("_ID")); // Get contact ID Uri dataUri = ContactsContract.Data.CONTENT_URI; // URI to get // data of // contacts Cursor dataCursor = getContentResolver().query(dataUri, null, ContactsContract.Data.CONTACT_ID + " = " + contctId, null, null);// Retrun data cusror represntative to // contact ID // Strings to get all details String displayName = ""; String nickName = ""; String homePhone = ""; String mobilePhone = ""; String workPhone = ""; String photoPath = "" + R.drawable.ic_launcher; // Photo path byte[] photoByte = null;// Byte to get photo since it will come // in BLOB String homeEmail = ""; String workEmail = ""; String companyName = ""; String title = ""; // This strings stores all contact numbers, email and other // details like nick name, company etc. String contactNumbers = ""; String contactEmailAddresses = ""; String contactOtherDetails = ""; // Now start the cusrsor if (dataCursor.moveToFirst()) { displayName = dataCursor .getString(dataCursor .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));// get // the // contact // name do { if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE)) { nickName = dataCursor.getString(dataCursor .getColumnIndex("data1")); // Get Nick Name contactOtherDetails += "NickName : " + nickName + "n";// Add the nick name to string } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) { // In this get All contact numbers like home, // mobile, work, etc and add them to numbers string switch (dataCursor.getInt(dataCursor .getColumnIndex("data2"))) { case ContactsContract.CommonDataKinds.Phone.TYPE_HOME: homePhone = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactNumbers += "Home Phone : " + homePhone + "n"; break; case ContactsContract.CommonDataKinds.Phone.TYPE_WORK: workPhone = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactNumbers += "Work Phone : " + workPhone + "n"; break; case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE: mobilePhone = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactNumbers += "Mobile Phone : " + mobilePhone + "n"; break; } } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) { // In this get all Emails like home, work etc and // add them to email string switch (dataCursor.getInt(dataCursor .getColumnIndex("data2"))) { case ContactsContract.CommonDataKinds.Email.TYPE_HOME: homeEmail = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactEmailAddresses += "Home Email : " + homeEmail + "n"; break; case ContactsContract.CommonDataKinds.Email.TYPE_WORK: workEmail = dataCursor.getString(dataCursor .getColumnIndex("data1")); contactEmailAddresses += "Work Email : " + workEmail + "n"; break; } } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)) { companyName = dataCursor.getString(dataCursor .getColumnIndex("data1"));// get company // name contactOtherDetails += "Coompany Name : " + companyName + "n"; title = dataCursor.getString(dataCursor .getColumnIndex("data4"));// get Company // title contactOtherDetails += "Title : " + title + "n"; } if (dataCursor .getString( dataCursor.getColumnIndex("mimetype")) .equals(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)) { photoByte = dataCursor.getBlob(dataCursor .getColumnIndex("data15")); // get photo in // byte if (photoByte != null) { // Now make a cache folder in file manager to // make cache of contacts images and save them // in .png Bitmap bitmap = BitmapFactory.decodeByteArray( photoByte, 0, photoByte.length); File cacheDirectory = getBaseContext() .getCacheDir(); File tmp = new File(cacheDirectory.getPath() + "/_androhub" + contctId + ".png"); try { FileOutputStream fileOutputStream = new FileOutputStream( tmp); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } photoPath = tmp.getPath();// finally get the // saved path of // image } } } while (dataCursor.moveToNext()); // Now move to next // cursor contactList.add(new Contact_Model(Long.toString(contctId), displayName, contactNumbers, contactEmailAddresses, photoPath, contactOtherDetails));// Finally add // items to // array list } } while (contactsCursor.moveToNext()); } return contactList; } } |
9. Now, you are all done, run your app and you will get the output as shown in video.
Thanks.
Subscribe to us and get the latest news.
4 Comments
sravani
Monday, March 26th, 2018Hi , i want source code of how to retrieve a list of contacts and then how to send and receive sms in android stuio
Sujeet
Thursday, October 25th, 2018Thank you so much..
shayan
Wednesday, April 10th, 2019my app is crash when it run
Dr. Droid
Thursday, April 11th, 2019Hi Shayan,
Can you share your error logs?
Thanks