Reading contact information using file descriptor in android

I'm having trouble getting Contacts from my contact list. I am using this code:

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); 

But I get an Exception :

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

Can someone help me with this?

+6
source share
1 answer

You can try to get the whole line and save it in the list of lines, for 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; } 
0
source

Source: https://habr.com/ru/post/926312/


All Articles