から電子メールを取得者の電子メールIDは、Androidの連絡先に、プログラム選択を取得する方法アンドロイドの連絡先リスト
すべてversion.iをサポートする必要があり、それは人のクラスで試してみましたが、プライマリ電子メール法は、事前に
感謝が推奨されていません
アスワン
から電子メールを取得者の電子メールIDは、Androidの連絡先に、プログラム選択を取得する方法アンドロイドの連絡先リスト
すべてversion.iをサポートする必要があり、それは人のクラスで試してみましたが、プライマリ電子メール法は、事前に
感謝が推奨されていません
アスワン
以前のAPIバージョンの場合は、Contacts
クラスを使用する必要があり、5以降の場合はContactsContract
クラスを使用する必要があります。
APIバージョンをクエリし、使用するクラスを決定する必要があります。
ねえアスワン 私はこれをやったことがないが、uのアイデアを与えることができます。
このコードは、電子メールを連絡先に追加することについてのアイデアを提供します。
import android.provider.Contacts.People;
import android.content.ContentResolver;
import android.content.ContentValues;
ContentValues values = new ContentValues();
// Add Abraham Lincoln to contacts and make him a favorite.
values.put(People.NAME, "Abraham Lincoln");
// 1 = the new contact is added to favorites
// 0 = the new contact is not added to favorites
values.put(People.STARRED, 1);
Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
Uri phoneUri = null;
Uri emailUri = null;
// Add a phone number for Abraham Lincoln. Begin with the URI for
// the new record just returned by insert(); it ends with the _ID
// of the new record, so we don't have to add the ID ourselves.
// Then append the designation for the phone table to this URI,
// and use the resulting URI to insert the phone number.
phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
values.clear();
values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
values.put(People.Phones.NUMBER, "1233214567");
getContentResolver().insert(phoneUri, values);
// Now add an email address in the same way.
emailUri = Uri.withAppendedPath(uri, People.ContactMethods.CONTENT_DIRECTORY);
values.clear();
// ContactMethods.KIND is used to distinguish different kinds of
// contact methods, such as email, IM, etc.
values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);
values.put(People.ContactMethods.DATA, "[email protected]");
values.put(People.ContactMethods.TYPE, People.ContactMethods.TYPE_HOME);
getContentResolver().insert(emailUri, values);
now you have to extract emaill from contact
import android.provider.Contacts.People;
import android.database.Cursor;
// Form an array specifying which columns to return.
String[] projection = new String[] {
People._ID,
People._COUNT,
People.NAME,
People.NUMBER
};
// Get the base URI for the People table in the Contacts content provider.
Uri contacts = People.CONTENT_URI;
// Make the query.
Cursor managedCursor = managedQuery(contacts,
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
// Put the results in ascending order by name
People.NAME + " ASC");
次に、このカーソルに2つのクエリーがあります。 今私は2つの変更を投影すると思います。上記のコードで電子メールを追加する際に使用したのと同じ定数を追加する必要があります。
あなたはこのすべてを得ることができますhere。