2010-12-17 12 views
0

「名前」は表示されますが、「番号」は表示されません。
誰かが間違いを犯した箇所を教えてください。アンドロイドで電話番号を取得していません

package org.testcont; 

import android.app.Activity; 
import android.content.ContentResolver; 
import android.content.ContentUris; 
import android.database.Cursor; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.Contacts; 
import android.provider.Contacts.People; 
import android.widget.EditText; 
import android.widget.TextView; 

public class testcontActivity extends Activity { 
    /** Called when the activity is first created. */ 
    TextView tvname; 
    TextView tvnumber; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     tvname = (TextView) findViewById(R.id.TextView01); 
     tvnumber = (TextView) findViewById(R.id.TextView02); 

     Cursor c=getContentResolver().query(People.CONTENT_URI,null,null,null,null); 
     while(c.moveToNext()){ 
     int name=c.getColumnIndexOrThrow(People.NAME); 
     String nm=c.getString(name); 
     tvname.setText(nm); 
     int number=c.getColumnIndexOrThrow(People.NUMBER); 
     String s=c.getString(number); 

     } 
     c.close(); 
    } 
} 

答えて

0

あなたはむしろあなたが連絡先の名前と番号を取得するには、この

android.provider.ContactsContract.CommonDataKinds.Phone 

クラスは、以下の変更を行い使用する必要があり、古いAPIを使用している:

Cursor c=getContentResolver().query(Phone.CONTENT_URI,null,null,null,null); 
int name=c.getColumnIndexOrThrow(Phone.DISPLAY_NAME); 
int number=c.getColumnIndexOrThrow(Phone.NUMBER); 
関連する問題