如何以编程方式获取android手机中的Google导入联系人。请帮助我。谢谢提前
答案 0 :(得分:1)
要获取Google帐户信息,Google提供了如何获取联系人,创建新帐户,添加照片的步骤。 请参阅此link
答案 1 :(得分:1)
这是我在Android新手时尝试过的课程。
public class ReadGoogleContact extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String[] GROUP_PROJECTION = new String[] {Groups._ID, Groups.TITLE };
Cursor groupCursor = getContentResolver().query(Groups.CONTENT_URI, GROUP_PROJECTION, null, null, Groups.TITLE);
if(groupCursor.getCount() > 0) {
while(groupCursor.moveToNext()) {
String groupId = groupCursor.getString(groupCursor.getColumnIndex(Groups._ID));
String groupName = groupCursor.getString(groupCursor.getColumnIndex(Groups.TITLE));
Log.i("GoogleGroup", "Group Id : " + groupId + " Group Name : " + groupName);
printContacts(groupName, groupId);
}
} else {
Log.i("GoogleGroup", "No any group found");
}
if(groupCursor != null || !groupCursor.isClosed())
groupCursor.close();
}
private void printContacts(String groupName, String groupId) {//getGroupWiseContacts(String id) {
Cursor cursor = this.managedQuery(Data.CONTENT_URI, new String[] {
Contacts.DISPLAY_NAME, Contacts._ID },
GroupMembership.GROUP_ROW_ID + " = ?",
new String[] { groupId }, Phone.TIMES_CONTACTED + " DESC");
Log.i("GoogleGroup", "___________ " + groupName + " ________________________");
if(cursor.getCount() > 0) {
while(cursor.moveToNext()) {
Log.i("GoogleGroup", "Contact id : " + cursor.getString(1) + " Display Name : " + cursor.getString(0));
}
} else {
Log.i("GoogleGroup", "No any contacts with this group");
}
if(cursor != null || !cursor.isClosed())
cursor.close();
}
}
您可以参考此docs
了解更多信息