2011-03-28 4 views
0

연락처를 클릭 할 때 전화 번호를받지 못합니다. 연락처 이름은 이지만 번호는 없습니다. 관련 게시물에 추천했지만 아직 만족하지 않으므로 나를 안내하십시오.연락처 선택 및 전화 번호 받기 및 전화

작업
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); 
     } 
    } */ 

답변

0
Cursor phones = etContentResolver() 
     .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
       null, 
       ContactsContract.CommonDataKinds.Phone.CONTACT_ID 
       + " = " + contactId, 
       null, null); 
while (phones.moveToNext()) { 
    String phoneNumber = phones.getString(
      phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 
} 
+1

하지 친구를 다음과 같이

내 코드입니다 –