2012-09-26 2 views
6

연락처 목록에서 연락처를 가져 오는 데 문제가 있습니다. 나는이 코드를 사용하고 있습니다 :android의 파일 설명자를 사용하여 연락처 정보 읽기

final Cursor Contact = cResolver.query(ContactsContract.Contacts.CONTENT_URI, null, 
       ContactsContract.Contacts._ID +" = " + Contact_ID, null,null); 
     Contact.moveToFirst(); 
     String lookupKey = Contact.getString(Contact 
       .getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); 

     Uri uri = Uri.withAppendedPath(
       ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey); 

     AssetFileDescriptor fd = null; 
     FileInputStream fis = null; 

     fd = cResolver.openAssetFileDescriptor(uri, "_ID"); 
     fis = fd.createInputStream(); 
     byte[] buf = new byte[(int) fd.getDeclaredLength()]; 
     fis.read(buf); 
     String vcardstring = new String(buf); 

을하지만 Exception 받고 있어요 :

java.io.IOException: read failed: EINVAL (Invalid argument) 
libcore.io.IoBridge.read(IoBridge.java:432) 

어느 한이 나를 도와 드릴까요?

+0

당신이 전체 스택 추적을 게시 할 수 있습니까? –

+0

안녕 AnasBakez, 나는 또한 동일한 문제에 직면하고있다. 해결책이 있다면 공유하십시오. –

+0

@abhishekkumargupta 아직 솔루션을 찾지 못한다면 해결책은 파일 디스크립터를 사용하지 않는 것입니다. 사용하는 데 몇 가지 문제가 있기 때문에 일부 장치/제조업체에서는 사용하지 않기 때문에 콘텐츠에서 원하는 모든 정보를 얻을 수 있습니다. 공급자가 수동으로. 나는 그것이 도움이되기를 바란다. – AnasBakez

답변

0

당신은 전체 라인을 얻을 시도하고, 문자열 목록의 예 저장할 수 있습니다 :

public List<String> getAnswers(int line) { 
    List<String> answerList = new ArrayList<String>(); 
    // Select All Query 
    String selectQuery = "SELECT * FROM " + TABLE_GERAL; 

    SQLiteDatabase db = this.getWritableDatabase(); 
    Cursor cursor = db.rawQuery(selectQuery, null); 

    cursor.moveToPosition(line); 

    for(int x=0; x<cursor.getColumnCount();x++){ 
     answerList.add(cursor.getString(x)); 
    } 

    return answerList; 
}