本文介绍了获取谷歌导入联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得在编程机器人phone.please帮助me.Thanks的谷歌联系人导入事先

How to get programatically the Google import contacts in android phone.please help me.Thanks in advance

推荐答案

下面是我想,当我为Android新手一类。

Here is a class which I tried when I was novice for 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();
    }
}

和更多信息,你可以参考这个文档

And more information you can refer this docs

这篇关于获取谷歌导入联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 11:52