0

連絡先IDと連絡先グ​​ループを取得するにはどうすればよいですか?私は次のコードを使用しました。これは、名前と電話番号を他のすべての情報に提供しますが、IDやグループは提供しません。

public void ExportContacts() {
            vCard = new ArrayList<String>();
            cursor = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
            int ss = cursor.getCount();
            if(cursor!=null&&cursor.getCount()>0)
            {
                cursor.moveToFirst();
                for(int i =0;i<cursor.getCount();i++)
                {

                    get(cursor);
                    Log.d("TAG", "Contact "+(i+1)+"VcF String is"+vCard.get(i));
                    cursor.moveToNext();
                }

            }
            else
            {
                Log.d("TAG", "No Contacts in Your Phone");
            }

        }

        public void get(Cursor cursor)
        {
            //cursor.moveToFirst();
            String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
            Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
            AssetFileDescriptor fd;
            try {
                String _id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                fd = mContext.getContentResolver().openAssetFileDescriptor(uri, "_ID");
                FileInputStream fis = fd.createInputStream();
                byte[] buf = new byte[(int) fd.getDeclaredLength()];
                fis.read(buf);
                String vcardstring= new String(buf);
                vCard.add(vcardstring);

                String storage_path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
                FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, true);
                mFileOutputStream.write(vcardstring.toString().getBytes());

            } catch (Exception e1) 
            {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

ファイルに書き込んだvCardにIDとグループ名を入れたい。誰か助けてもらえますか?

4

1 に答える 1

0

必要な ID に応じて、これまたはこれを ID フィールドに使用できます。

グループ名は少し厄介な可能性があります:これはグループ タイトルの行であり、必要なものかもしれませんが、グループが定義されていない場合に備えて、おそらく適切なエラー チェックを行う必要があります。

編集: グループ ID はこちらで確認できます。

于 2012-05-20T12:28:04.290 に答える