select a contact and get phone number and call it
<p>I don't get a phone number when I click on a contact, I get only a contact name
but no number. I was referred to a related post but still not satisfied so
please guide me.</p>

<p>My code is as follows:</p>

<pre><code>package com.Call_setup;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.widget.ListAdapter;
import android.widget.TextView;

public class Call_setup extends Activity {
    /** Called when the activity is first created. */
    Intent callIntent;
    private ListAdapter mAdapter;
    public TextView pbContact;
    public static String PBCONTACT;
    public static final int ACTIVITY_EDIT=1;
    private static final int ACTIVITY_CREATE=0;
    private static final int PICK_CONTACT = 0;
    private static final int PICK_CONTACT_REQUEST = 2;
      String id;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        call();
        //  onReceive(this,callIntent);
        IncomingCallReciever ic = new IncomingCallReciever();
        ic.onReceive(getApplicationContext(), callIntent);
    }
    private void call() {
        try {
          // Intent callIntent = new Intent(Intent.ACTION_CALL);
            /*Intent callIntent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
            callIntent.setData(Uri.parse("tel:123456"));
            startActivity(callIntent);
           // stopService(callIntent);
            */


            Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
        startActivityForResult(intent, PICK_CONTACT);
            }
            catch (ActivityNotFoundException activityException) {
           //  Log.e("helloandroid dialing example", "Call failed", e);
        }


    }
    @Override
    public void onActivityResult(int reqCode, int resultCode, Intent data) {
      super.onActivityResult(reqCode, resultCode, data);
      ContentResolver cr = getContentResolver();
      switch (reqCode) {
        case (PICK_CONTACT) :
          if (resultCode == Activity.RESULT_OK) {
            Uri contactData = data.getData();
            Cursor c =  managedQuery(contactData, null, null, null, null);
            if (c.moveToFirst()) {
              String name = c.getString(c.getColumnIndexOrThrow(People.Phones.NAME));
              String contactId = c.getString(c .getColumnIndex(ContactsContract.Contacts._ID));
              // Intent callIntent = new Intent(Intent.ACTION_CALL);

              System.out.println("number key is : " + name);
              System.out.println("reqCode is : " + reqCode);
              System.out.println("resultCode is : " + resultCode);
              System.out.println("contactId is :" + contactId);

             // String phoneNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
              /*callIntent.setData(Uri.parse("tel:"+number));
              startActivity(callIntent);*/

            }

          }
          break;
      }

   }
      }

    /*public void onReceive(Context context, Intent intent) {
        MyPhoneStateListener phoneListener=new MyPhoneStateListener();
        TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

        telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);*/

   /* public void onReceive( final Context context, final Intent intent ) 
    { 
      Log.i( "l", "onReceive()" ); 
      Log.i( "l", "context: " + context ); 
      Log.i( "l", "intent: " + intent ); 
      if( intent.getAction().equals( Intent.ACTION_NEW_OUTGOING_CALL ) ) 
      { 
        String number = intent.getExtras().getString( Intent.EXTRA_PHONE_NUMBER ); 
        Log.i( "l", "number: " + number ); 
      } 
    } */
</code></pre>
