我在从联系人列表中获取联系人时遇到问题。我正在使用此代码:
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)
您可以尝试获取整行并将其保存在字符串列表中,例如:
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;
}