Open device contacts list at button click event

前端 未结 4 1821
名媛妹妹
名媛妹妹 2021-01-14 12:34

How can i open Android device contacts list at button click event.

4条回答
  •  无人及你
    2021-01-14 12:46

    You can use this source code as a reference:

    import android.app.Activity; 
    import android.content.Intent;
    import android.database.Cursor;
    import android.net.Uri;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.provider.ContactsContract;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class Test1Activity extends Activity  {
    
        private static final int PICK_CONTACT_REQUEST = 1;
    
        private static final int PICK_CONTACT = 0;
    
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button pickContact = (Button) findViewById(R.id.button1);
    
            pickContact.setOnClickListener(new OnClickListener() 
            {
                public void onClick(View v) {
    
                    Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                    i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);   
    
                    startActivity(i);
                }
            });
    
        }
    }
    

提交回复
热议问题