Android Api を使用して VCard 形式で Android デバイスの連絡先を読み込もうとしています。同じリンクが 1 つ見つかりました: Android contatcs vcard API
同じコードを書き込もうとしていますが、ルックアップキーを取得できないため、機能しません。
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
int num = cur.getCount(); // I get 2 , as there are two contacts
String lookupKey = cur.getString(cur.getColumnIndex(Contacts.LOOKUP_KEY));
// The above line gives error : android.database.CursorIndexOutOfBoundsException:
// Index -1 requested, with a size of 2
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd = resolver.openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] b = new byte[(int)fd.getDeclaredLength()];
fis.read(b);
String vCard = new String(b);
sb.append(vCard);
上記のコードのルックアップキーを取得する方法を教えてください。または、Android api を使用して連絡先の VCard 形式を取得する他の方法があります。