2012-03-01 4 views
1

私はユーザーの電話に連絡先のリストを作成しましたが、今私はどのようにそれを作成するユーザーの写真(fbからではない)を追加したいですか? :D これは私のコードです:ユーザーの連絡先の写真を電話からListViewに追加しますか? :D

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    ContentResolver cr = getContentResolver(); 
    Cursor cursor = cr.query(Uri.parse("content://sms/inbox"), null, null, 
      null, null); 

    int indexBody = cursor.getColumnIndex("body"); 
    int indexAddr = cursor.getColumnIndex("address"); 

    if (indexBody < 0 || !cursor.moveToFirst()) 
     return; 

    smsList.clear(); 

    do { 
     String str = "Sender : " + cursor.getString(indexAddr) + "\n" 
       + cursor.getString(indexBody); 
     smsList.add(str); 
     // ADDRESS[total] = cursor.getString(indexAddr); 
     // total++; 
    } while (cursor.moveToNext()); 

    ListView lvSms = (ListView) findViewById(R.id.SMSList); 
    lvSms.setAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, smsList)); 

    // cursor.requery(); 
    lvSms.setOnItemClickListener(this); 
} 

が、私はこのコードでリストを作成:

do { 
     String str = "Sender : " + cursor.getString(indexAddr) + "\n" 
       + cursor.getString(indexBody); 
     smsList.add(str); 
     // ADDRESS[total] = cursor.getString(indexAddr); 
     // total++; 
    } while (cursor.moveToNext()); 

    ListView lvSms = (ListView) findViewById(R.id.SMSList); 
    lvSms.setAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, smsList)); 

    // cursor.requery(); 
    lvSms.setOnItemClickListener(this); 

ザッツすべてを、私はビットマップを使用しなければならないことが判明し、それは本当ですか? おかげですべて:D

PS:D

答えて

2
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, 
       contactId); 
     Uri photoUri = Uri.withAppendedPath(contactUri, 
       Contacts.Photo.CONTENT_DIRECTORY); 
     Cursor cursor = getContentResolver().query(photoUri, null, null, null, 
       null); 

このクエリを使用して、あなたの連絡先にユーザーの写真のために画像のURLを取得することができます:私はいくつかの間違いのが行われた場合、英語は、とても残念私の母国languangeではありませんリストでは、リストに名前と番号を表示するために、Baseまたはその他のカスタムアダプターが必要です。

+0

ありがとう:Dこのコードを実装する場所はどこですか?getContentResolver( "content:// sms/inbox")からのカーソルがすでにあります。私のアプリが応答しなくなった。助けてください、ありがとう:D –

+0

http://stackoverflow.com/questions/8634770/fetch-contact-photo-in-android-gives-null – Karthi

+0

ありがとうございます:Dしかし私はすでにそれを見ましたが、私はそれを理解していません(私は初心者です)ありがとう:D –

関連する問題