6

我在从我的联系人列表中获取联系人时遇到问题。我正在使用这段代码:

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)

谁能帮我这个?

4

1 回答 1

0

You can try get the whole line and save it in a String List, an example:

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;
}
于 2014-03-11T14:55:53.163 回答