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)
任何一個能幫助我嗎?
您可以張貼整個堆棧跟蹤? –
嗨AnasBakez,我也面臨同樣的問題。如果你有解決方案,那麼請分享。 –
@abhishekkumargupta如果你仍然沒有找到解決方案,解決方案是不使用文件描述符,因爲我遇到了一些使用它的問題,一些設備/製造商不使用它,所以我現在得到我想要的內容的所有信息提供者手動。我希望這會有所幫助 – AnasBakez