Friday, June 7, 2013

Android Get Phone Contacts details with Contact Image | Code for getting phone contact detail in Android | How to get phone number in Android phone programmatic

Hello Friends!
Today I am going to share code for getting phone contact detail from your android phone.
It will pick all the phone number, email and profile picture also.
Just copy paste below code and enjoy..

1)MainActivity.java


package com.example.phonecontactdetail;

import java.io.FileNotFoundException;
import java.io.IOException;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.widget.TextView;

public class MainActivity extends Activity {
 TextView textDetail;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  textDetail = (TextView) findViewById(R.id.textView1);
  readContacts();
 }

 public void readContacts() {
  StringBuffer sb = new StringBuffer();
  sb.append("......Contact Details.....");
  ContentResolver cr = getContentResolver();
  Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
    null, null, null);
  String phone = null;
  String emailContact = null;
  String emailType = null;
  String image_uri = "";
  Bitmap bitmap = null;
  if (cur.getCount() > 0) {
   while (cur.moveToNext()) {
    String id = cur.getString(cur
      .getColumnIndex(ContactsContract.Contacts._ID));
    String name = cur
      .getString(cur
        .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

    image_uri = cur
      .getString(cur
        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
    if (Integer
      .parseInt(cur.getString(cur
        .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
     System.out.println("name : " + name + ", ID : " + id);
     sb.append("\n Contact Name:" + name);
     Cursor pCur = cr.query(
       ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
       null,
       ContactsContract.CommonDataKinds.Phone.CONTACT_ID
         + " = ?", new String[] { id }, null);
     while (pCur.moveToNext()) {
      phone = pCur
        .getString(pCur
          .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      sb.append("\n Phone number:" + phone);
      System.out.println("phone" + phone);
     }
     pCur.close();

     Cursor emailCur = cr.query(
       ContactsContract.CommonDataKinds.Email.CONTENT_URI,
       null,
       ContactsContract.CommonDataKinds.Email.CONTACT_ID
         + " = ?", new String[] { id }, null);
     while (emailCur.moveToNext()) {
      emailContact = emailCur
        .getString(emailCur
          .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
      emailType = emailCur
        .getString(emailCur
          .getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
      sb.append("\nEmail:" + emailContact + "Email type:" + emailType);
      System.out.println("Email " + emailContact
        + " Email Type : " + emailType);

     }

     emailCur.close();
    }
    
    if (image_uri != null) {
     System.out.println(Uri.parse(image_uri));
     try {
      bitmap = MediaStore.Images.Media
        .getBitmap(this.getContentResolver(),
          Uri.parse(image_uri));
      sb.append("\n Image in Bitmap:" + bitmap);
      System.out.println(bitmap);

     } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }

    }
   
    
    sb.append("\n........................................");
   }

   textDetail.setText(sb);
  }
 }

}

2)activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="10dp"
        android:text="TextView" />
  
</RelativeLayout>

Please comment for suggestion and help!
Thanks!

112 comments :

  1. Thanks for this awesome project but let me ask, its failing to emulate...am using the target SDK as 15 and minimum SDK as 8...what could be the problem

    ReplyDelete
    Replies
    1. Hi Moris,It should work just put read contact permission in your manifest.xml-


      And please test it on mobile phone only not on emulator... And if your device version is lower than 11 in that class please add below line for contact photo-
      int SDK_INT = android.os.Build.VERSION.SDK_INT;
      // System.out.println("******API Lavel*********"+SDK_INT);
      if(SDK_INT>=11){
      image_uri = cur.getString(cur
      .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
      }

      Delete
  2. i was only lacking the permission, thanks

    ReplyDelete
  3. awesome code.!.can u plz post the total project code for an contact app..i'm working on a project on this..bt i am stuck at listview..i am not able to display the contact names in the listview dynamically from the database..can u help?

    ReplyDelete
  4. Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
    ArrayList> contactData = new ArrayList>();
    while (cursor.moveToNext()) {
    try{
    int i1 = cursor.getColumnIndex(ContactsContract.Contacts._ID);
    String contactId = cursor.getString(i1);


    please explian me each line detailly

    ReplyDelete
  5. Hi Srujana! Please find the explanation below-
    //this is the cursor query for getting all contact detail from android phone database
    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
    //contactData is a collection for storing record for future use
    ArrayList> contactData = new ArrayList>();
    //this line for check condition one by one record from cursor query
    while (cursor.moveToNext()) {
    try{
    //here you will ger id of phone contact which is used as primary key
    int i1 = cursor.getColumnIndex(ContactsContract.Contacts._ID);
    //and i think above line is extra here no need to convert it into string again
    //you can use below line-
    String id = cur.getString(cur
    .getColumnIndex(ContactsContract.Contacts._ID));

    Thanks,

    ReplyDelete
  6. hello manish...its shows only text view ...?whats the problme..?

    ReplyDelete
    Replies
    1. Are you testing on phone or on emulator? and do you have phone contacts there?

      Delete
  7. how to get all contact details? like organization,region,city,country ?

    ReplyDelete
    Replies
    1. yes you can get all data from contact detail what android provide us. just use constructor of ContactsContract.Contacts like below, i am getting id. just replace _ID with your key. And please change type of int i1 to what you needed like String, Boolean etc.

      int i1 = cursor.getColumnIndex(ContactsContract.Contacts._ID);

      note: you can get only that data what android provide us.

      Delete
  8. Hi Manish,

    Thanks for the code. But the scrolling functionality is not working. And i am not getting all contacts. Can u please help me?

    ReplyDelete
    Replies
    1. Just change your Relative Layout to ScrollView and if it not allow because scrollview only can have one direct child then add your Relative Layout inside Scroll-View and it will work fine.

      Delete
    2. Can u plz tell me, how to add a scroll view in the layout bcoz im new to android. Thanks in advance.

      Delete
  9. Hi Manish

    Thanx for your reply. Now it's working fine. Can you help me with Source code to how to get GSM Signal Strength in Android?

    ReplyDelete
    Replies
    1. Please try this code may be it will help you-

      TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
      CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
      CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
      cellSignalStrengthGsm.getDbm();

      And don't forget to add permision in your manifext.xml file for telephony manager.

      Delete
  10. Hi Manish,

    One more thing i want to clarify. It is displaying the list of contacts in a xml file. But i need to enable the call functionality to that numbers. Is there any possibility? Please help me in this regard.

    ReplyDelete
    Replies
    1. Just get phon number from list and set onItemClickListner on that Listview and inside that call a intent for make a call like-

      dataList.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView parent, View v,
      final int position, long id) {
      // TODO Auto-generated method stub
      Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
      startActivity(intent);
      }
      });

      And most Important add permision in your manifest-

      Delete
  11. Hi Manish,

    Thanks for the post. Can you help me to retrieve contact details of a particular number.

    ReplyDelete
    Replies
    1. so just add a line in that query like-
      if(phone.equals("921111111"){
      sb.append("\n Phone number:" + phone);
      }

      It will append only that contact detail..

      Delete
    2. i want get mob no bt this code is not working..

      Delete
    3. @Praroop- Telephony Manager does not guarantee to get the user mobile number, so kindly refer other method like take input from user and validated it using SMS.

      Delete
  12. Hello ,can you please specify how to retrieve Photo uri of a contact in API< 11 ,

    ReplyDelete
    Replies
    1. I think there is no way for below API level 11. Well if you got anything please let me know, I am looking for it.

      Thanks!

      Delete
  13. Hi Manish,

    Can you help me by providing a source code to play a video file in Android through wifi. Awaiting for your response.

    Thanks,
    Mahesh K.

    ReplyDelete
    Replies
    1. Hi Mahesh, your question is interesting and challenging too. So how do you want play video? you want play your android device video from outside using any device or something else?

      Delete
    2. Hi Manish,

      Sorry for the delay. Actually i have an wifi URL. And i want to play it in my application. And actually the requirement is i want the source code for Youtube functionality like in Landscape mode when we press an icon then the video will get stretch and when we again press that icon then it will come to normal state and vice versa. I want the total source code for it. Can you provide me? Awaiting for your response.

      Thanks,
      Mahesh K.

      Delete
    3. Hi Manish,

      I am waiting for your reply. Can you please provide the source code. So, that it will be more helpful to me. And i had another small doubt. I have put my application in Google Playstore. But sometimes i am getting crash reports. And one of the most common crash report is

      java.lang.NullPointerException
      at com.reliance.aptv.MainActivity.b(Unknown Source)
      at com.reliance.aptv.bj.c(Unknown Source)
      at com.reliance.aptv.by.a(Unknown Source)
      at com.reliance.aptv.MainActivity.b(Unknown Source)
      at com.reliance.aptv.bs.run(Unknown Source)
      at android.os.Handler.handleCallback(Handler.java:587)
      at android.os.Handler.dispatchMessage(Handler.java:92)
      at android.os.Looper.loop(Looper.java:130)
      at android.app.ActivityThread.main(ActivityThread.java:3714)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:507)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
      at dalvik.system.NativeStart.main(Native Method)
      Can any help me why this crash report is coming.

      Thanks in advance,

      -Mahesh Babu K.

      Delete
  14. thanks for this example , and i have one query how to fetch the contact image and set into listview ,please help

    ReplyDelete
    Replies
    1. Please check this line of code-

      if (cur.getCount() > 0) {
      while (cur.moveToNext()) {
      String id = cur.getString(cur
      .getColumnIndex(ContactsContract.Contacts._ID));
      String name = cur
      .getString(cur
      .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
      int SDK_INT = android.os.Build.VERSION.SDK_INT;
      // System.out.println("******API Lavel*********"+SDK_INT);
      if(SDK_INT>=11){

      image_uri = cur
      .getString(cur
      .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
      if (image_uri != null) {
      // System.out.println(Uri.parse(image_uri));


      try {
      Bitmap bitmap = MediaStore.Images.Media
      .getBitmap(this.getContentResolver(),
      Uri.parse(image_uri));
      // System.out.println(bitmap);

      imageBase64String = Helper.encodeTobase64(bitmap);
      objContact.put("profile_img", imageBase64String);

      } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }

      }

      }

      Delete
    2. hi manish this is ok,but how i get the phone number and name by use of cursor and give that into simplecursor adopter and finally i set that adopter into listviw and now my query how can i give the photouri to smplecursor adopter , please help

      Delete
  15. hi manish and one more query,how i can able to display the phone number and name by use of cursor and give that into simplecursor adopter and finally i set that adopter into listview,and i also use the search view for the contact name whatever the user type in the editbox based on i can able to filter and i also display in the listview ,and i am use contextmenu for longpress the contact in that menu have some options then i can able to us thougs options and if i press back button in the device then on resume activity is open but for me the app is crashed and it give error as unable to resume activity..please help

    ReplyDelete
  16. Hello Manish,

    Am not getting bitmap image, it showing just like Bitmap.android.graphics.Bitmap@4b84533 .

    Please help me

    ReplyDelete
    Replies
    1. From there you are getting URL only not and bitmap so you have to use Image Donwloader from URL some thing like that-

      private Bitmap downloadImage(String url) {
      Bitmap bitmap = null;
      InputStream stream = null;
      BitmapFactory.Options bmOptions = new BitmapFactory.Options();
      bmOptions.inSampleSize = 1;
      try {
      stream = getHttpConnection(url);
      bitmap = BitmapFactory.decodeStream(stream, null, bmOptions);
      stream.close();
      }
      catch (IOException e1)
      {
      e1.printStackTrace();
      }
      return bitmap;
      }


      Read more: http://www.androidhub4you.com/2013/09/google-account-integration-in-android.html#ixzz2wKnSyYCY

      Delete
  17. hi manish can you please tell me how to avoid duplication of numbers in the list. I am able to populate all my contacts in a list view using a custom cursor adapter now i want to just display one number once be it defined as 01234567890 or +911234567890 or 1234567890.
    i just want it to be displayed it once. kindly help

    ReplyDelete
  18. Excellent Tutorial .. I was referring to the official tutorial which was a lot complicated (https://developer.android.com/training/contacts-provider/retrieve-names.html)

    Meanwhile i forgot to put the while loop in there at first (ie while(cur.moveToNext()) and was getting CursorOutofBoundsException .. After lot of check, i found that the cursor must be moved to first to read from it. Then i realized why the while loop works automatically.. Hope this might help someone stuck with same problem :)

    Thanks for your code.

    ReplyDelete
  19. can you plz tell me how to get contact added date and time or last update time when contact modified..

    ReplyDelete
    Replies
    1. I don't think you can get last modified date and time. If you got anything please let me know, i am interested.

      Delete
  20. hi ramish its work show all the contacts in logCat but it show textview of Xml in android phone please help as soon as possible

    ReplyDelete
    Replies
    1. it should work. please recheck my demo code.
      If any crash report please share with me.

      Thanks!

      Delete
  21. can you plz tell me if i have 1000 contact in phone then how much tym take to read and write it my local db.........

    ReplyDelete
    Replies
    1. its depend on your data, no one can calculate it.

      Delete
  22. I am using mapv2 fragment in XML and use it in fragment.......
    in oncreateview( ) i get it from layout and show correctly.......now when i press back and go to again on fragment its error for duplicate id........so when i search for solving this I found in ondestroyview( ) we release the mapv2 fragment I done this and app running correctly but for a while(1 sec) screen goes to black where map shows .......

    ReplyDelete
    Replies
    1. I am not getting you. Well create your varaible declaration as private like-
      private TextView textView1;

      May be it solve your problem.

      Delete
  23. How to use Mapv2 with tabbar where 2 different tab shown map.....please help

    ReplyDelete
    Replies
    1. Is any exception here? I never try it but it should work.
      You are trying with action bar tab or old one? If using action bar then just bind your map into fragment.

      Delete
  24. Hello Brother, i getting error to run the above code in both Android Mobile Phone and also in Emulator...


    Error is: "phone contact detail is stopped"

    ReplyDelete
    Replies
    1. Try to call readContacts(); method inside Async task class. If you have given permission in manifest and everything ok then only main thread issue might be here so use background thread to get contact detail.

      Delete
  25. hello, i just want to get all contact name, number or photo of contact in listview.
    so please help me...???

    ReplyDelete
  26. Hi Thanks for the great Example Manish, I am getting images and contact numbers fine but both are not coming simultaneously.. please help me..

    ReplyDelete
  27. By that im getting image and contact name different.....and while im scrolling list view im getting FC

    ReplyDelete
  28. It's really satisfied.
    VERY VERY GOOD.
    Thanks you

    ReplyDelete
  29. hi everyone
    i implemented this code in my project but its shows only empty page

    ReplyDelete
  30. Working Code,thanks.But taking around 5 secs to load 100 contacts in my phone.can't something be done to make it fast!!

    ReplyDelete
    Replies
    1. Fetching the data from phone will take some time, so till then you can show progress dialog.

      Delete
  31. Hi. thanks @Manish for sharing this, i have just copied and pasted this code into my developer environment and added the READ_CONTACTS permission to my manifest file and after running the code in the emulator, it failed with the following stack trace from logcat: http://pastebin.com/zZUENdCu

    ReplyDelete
  32. setting android:minSdkVersion to 11 in the manifest file instead of 8 fixed the error

    ReplyDelete
    Replies
    1. There was problem with contact image. Image work above the version 11. You can make a check in your code over the get uri of image.

      Delete
  33. hi Manish!
    this is one awesome tutorial,works like a charm.
    now i want to add List view in the same code,have tried but no luck yet :/ Can u help?
    thanks in advance :) keep sharing awesome tutorials.

    ReplyDelete
  34. Hi Manish,

    The code works fine, I can able to find my contact lists in the Logcat through SOP statements, But I'm wondering why this doesn't appear when I run the application in my mobile.

    The o/p occurs as:

    ......Contact Details....
    ..................................
    .................................

    ReplyDelete
  35. greate example - in my try it fails on "textDetail.setText" do you have any suggestions ?

    regards
    Andrzej

    ReplyDelete
  36. This comment has been removed by the author.

    ReplyDelete
  37. Hi Manish Srivastava,
    Iam not a programmer, but I would like to have this app (view contacts with name, number and picture).
    kindly suggest an app if it is available on google play.

    ReplyDelete
  38. I am creating my app account successfully in device Now i am trying to fetch all contact and show my app name like whats app (which number is register with my app) After searching a lot a I don't get write answer for understanding how its work. Please help

    ReplyDelete
    Replies
    1. Step 1- Get all the phone contact number and their unique Id and send it to server in service class so user did not know about background process.
      Step 2- Server side you need match all the database with your numbers list and return true for which number into your server database and false for other.
      Step 3- Now at Android side you need to display that number from your phone book which status is true.
      Step 4- And for future if some one add any new contact in their phone book just you need to use broadcast receiver for add new contact and send that contact on server i background and match with server data.

      I think that's all you have to do.
      Step

      Delete
  39. dear sir i want to fetch all the phone calls and messages in android app and i want after every 24 hours all detail goes to my mail....hoping best response.

    ReplyDelete
    Replies
    1. Let me clear your doubt first. Actually without user interaction you can't use their email application to send email in background thread. So if you really want to send all detail on email follow below steps-

      1)Write a web service for sending all history on server.
      2)From server side you can store it into database or you can email all data to any email id.
      3)At client side on your phone you need to implement Alarm Manager which will send data to server after every given interval(like 24 hour).
      4)And for fetching all history follow below links-

      http://www.androidhub4you.com/2014/02/android-sms-history-get-messages-record.html
      http://www.androidhub4you.com/2013/09/android-call-history-example-how-to-get.html

      Hope it will help you!

      Delete
    2. but sir using server for fetch mean only for personal use....but i want to make application for all users
      1) I install a app in the user mobile
      2) fill the email
      3) after fill i hide the app

      now user dont know all details of there calls and messges come to my mail id

      Delete
    3. No you are wrong, using server you can access to all users record with their unique phone id and sent it to where you want. You can purchase server email to send email like you revived many email from advertising company so they are using a mail server to send email.

      And what you are planning to use phone email and hide the app and all not possible. Android does not allow us to do it for security reason.

      Think by yourself if any application like Facebook sending email using your Gmail to anyone is it good thing? Or is it possible? Answer is no.

      Delete
    4. ok sir thanks but im trying to make spy app like this......thnx for gr8 response :)

      Delete
  40. I need to retrieve only device contact please help me

    ReplyDelete
    Replies
    1. not google, nor any other contacts only and only device contact or sim

      Delete
    2. have a look at below line-
      if (Integer
      .parseInt(cur.getString(cur
      .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
      }

      It will go inside if condition only if contacts have phone number.

      Delete
  41. but What about images? It's not showing.

    ReplyDelete
    Replies
    1. Did you check below line-
      image_uri = cur
      .getString(cur
      .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));

      from here you will get the image URI then use image downloader to display them.

      Delete
  42. Hi Manish,

    This awesome tutorial. But if there is a 5000 contacts in a phone , its slow at the first time of loading.I just fetch name and image .but when the size goes to 3000 to 5000, it is slow. can you please give as an idea for fast fetching.

    ReplyDelete
    Replies
    1. Hi Binil, I never tried with large number of data but I hope Lazy Loading and Async Task should help you.

      Delete
  43. // Column data from cursor to bind views from
    String[] columns = new String[]{ContactsContract.CommonDataKinds.Phone.PHOTO_URI, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER};

    // View IDs which will have the respective column data inserted
    int[] to = new int[]{R.id.contactImage, R.id.name, R.id.number};

    SimpleCursorAdapter madapter = new SimpleCursorAdapter(this, R.layout.item_activity, cursor, columns, to, 0);
    ListView listView = (ListView) findViewById(R.id.contactList);
    listView.setAdapter(madapter);

    hi Manish.,
    I have the above code. I am trying to display the contact list by sending it to adapter. everything is working fine am getting name,phone no. and image. problem is am not sure how can i place default image. if i dont have image in the contact list. Please help me in this.

    ReplyDelete
  44. Hello Manish....I want to retrieve a single contact from phonebook after verifying whether the MSISDN is 13 digit or not. If its 13 digit only then i can fetch the contact otherwise it wont allow me. Kindly help ....

    ReplyDelete
  45. Manish Sir..i created.netwebservices to fetch the vehicle details(i,e)id,name,phneno,chasis no..etc from SQL database..i want to fetch these details from webservices ..And details should come within listview while clicking onclick btton .please help me sir..

    button button1=(Button)findViewById(R.id.button1);

    btton1.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View view) {
    ListView = (ListView) findViewById(R.id.listview1);
    after which adapter i have to use??????????????????????

    please HELPPPP MMEEE sir..


    ReplyDelete
  46. anish Sir..i created.netwebservices to fetch the vehicle details(i,e)id,name,phneno,chasis no..etc from SQL database. webservices details . should come within listview while clicking onclick btton .please help me sir..

    button button1=(Button)findViewById(R.id.button1);

    btton1.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View view) {
    ListView = (ListView) findViewById(R.id.listview1);
    after which adapter i have to use??????????????????????

    please HELPPPP MMEEE sir..

    ReplyDelete
  47. Replies
    1. I dont know how to work with Asyn Task..Can u eXplain it

      Delete
    2. Mr manish i m Making a SPy app for myCollege Project...ANd honestly Speakin I Not well knew about Android..its seem difficulty for me ..i want call detisl and sms details and then so send to mail..but all this should happen in background?...

      can u make a help?

      Delete
  48. Hi Manish,How to get TYPE(Mobile,Home,Work,Work FAX, Home Fax and Other etc) of mobile number.

    ReplyDelete
  49. can anyone help me ...i want to do email task in everyu 1 hour without opening an app...somebody???

    ReplyDelete
  50. thanks for your useful code
    i have an problem:
    when i save the code,these lines are removed by itself "import android.provider.ContactsContract;
    import android.widget.TextView;"
    and then i got errors for "Contacts" , "CommonDataKinds" , "textDetail"
    whats the problem? what should i do???

    ReplyDelete
    Replies
    1. Please check your package name, it's seems R error. Please check your import for R.java.

      Delete
  51. Mr Mainsh how to create ap app who record the android screen ?

    ReplyDelete
    Replies
    1. As per my understanding you can't create a screen recorder app but above version 4.0 you can record your screen using adb command. In this case your phone must be connected with eclipse or android studio. Google for step to record your screen using adb command.

      Thanks!

      Delete
  52. how can't share a video file via shareit

    ReplyDelete
  53. Hey i have to send all these contacts on a server.and i have to send in json format.
    Can you tell me how to achieve this task plzzz

    ReplyDelete
    Replies
    1. public JSONArray readContacts() {
      JSONArray jsonArrayContacts = new JSONArray();
      JSONObject jsonContacts = new JSONObject();
      try {
      ContentResolver cr = getContentResolver();
      Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
      String phone = null;
      if (cur.getCount() > 0) {
      while (cur.moveToNext()) {
      String id = cur.getString(cur
      .getColumnIndex(ContactsContract.Contacts._ID));
      String name = cur
      .getString(cur
      .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

      if (Integer
      .parseInt(cur.getString(cur
      .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {

      Cursor pCur = cr.query(
      ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
      null,
      ContactsContract.CommonDataKinds.Phone.CONTACT_ID
      + " = ?", new String[]{id}, null);
      while (pCur.moveToNext()) {
      phone = pCur
      .getString(pCur
      .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      jsonContacts = new JSONObject();
      jsonContacts.put("name", name);
      jsonContacts.put("number", phone);
      jsonArrayContacts.put(jsonContacts);
      }

      pCur.close();
      }

      }

      }
      } catch (Exception e) {

      }
      return jsonArrayContacts;
      }

      Delete
  54. hello, Manish, I need android code to send contact details to my email or any other phone number. I would like to help getting this code.

    ReplyDelete
    Replies
    1. 1) You can't send contact detail direct to email address for this you need to write web-services and then using email server you can send it anywhere.

      2)You can send it over the sms in background but there are a lot of contacts and our SMS limit is 160 char so it will charge a lot so think before to implement it.

      All the code are above, do what you want to do with it.
      Thanks

      Delete
  55. Manish how to get any type of numbers in the image...

    ReplyDelete
    Replies
    1. in the image? I am not getting you. I guess you want use numbers as CHEPTA right? Well you can write number in any textview and you can take screenshot of that programmatically and you can use it where you want.

      Delete
  56. Hello, Manish Can you help me code to send this contact list as a message to another number. Thanks in advance

    ReplyDelete
    Replies
    1. Well contacts list contain a lot of data so sending them as a message will cost to user. Below is the link you can follow-

      http://www.androidhub4you.com/2013/10/send-sms-in-background-in-android-send.html

      Delete
    2. Thanks Manish, the above links works fine, but how can I connect thecontact list code and the send SMS-in background. Thanks in advance

      Delete
  57. how can i get the user contacts and save into the file

    ReplyDelete
  58. How can i save the contacts in a file

    ReplyDelete
  59. how can i access contacts in another phone? :)

    ReplyDelete
  60. sir...i was try to run this code but there is exception in this code..i can't handle them..so what i do,

    ReplyDelete
  61. Hi Manish,
    I am in search of apple wallet kind of animation for android. Can you please help me out of this.
    Link 1 : https://github.com/3lvis/CardStack
    Link 2 : https://android-arsenal.com/details/1/3096

    It will be very helpful if you can suggest something to achieve wallet kind of animation.

    Regards


    Ritesh Agrawal
    Skype : nm.ritesh

    ReplyDelete
  62. Is there any possibility to get all contacts and emails through one query

    ReplyDelete

Note: Only a member of this blog may post a comment.