How can I launch the 'Add Contact' activity in android

后端 未结 8 604
感情败类
感情败类 2020-11-30 00:15

Can you please tell me how to launch the Add Contact\' activity in android? Thank you.

相关标签:
8条回答
  • 2020-11-30 00:18

    This should be the snippet your are looking for:

    Intent addContactIntent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
    addContactIntent.putExtra(Contacts.Intents.Insert.NAME, "Jean-Claude"); // an example, there is other data available
    startActivity(addContactIntent)
    
    0 讨论(0)
  • 2020-11-30 00:19

    These two lines do the trick:

        Intent intent = new Intent(Intent.ACTION_INSERT, 
                                   ContactsContract.Contacts.CONTENT_URI);
        startActivity(intent);
    
    0 讨论(0)
  • 2020-11-30 00:20

    If you need to add a phone number to an existing contact or create a new one (just as the native dialer does with a new phone number) this code might be just what you need:

    final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.putExtra(Insert.PHONE, digits);
    intent.setType(People.CONTENT_ITEM_TYPE);
    startActivity(intent);
    

    Just take a look at the Android's source code for the DialpadFragment class, search for the method getAddToContactIntent(String digits).

    But as the People class is deprecated in api 10 you may want to use this line instead:

    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    
    0 讨论(0)
  • 2020-11-30 00:20
    Intent localintent = new Intent("android.intent.action.INSERT",ContactsContract.Contacts.CONTENT_URI);
    localintent.putExtra("phone", phoneNumber);
    startActivity(localintent);
    
    0 讨论(0)
  • 2020-11-30 00:25

    This post may help you out or at least point you in the right direction.

    Hope this helps.

    Update 05/11/2015:

    Per the comments, check out vickey's answer below for the appropriate solution.

    0 讨论(0)
  • 2020-11-30 00:28

    If you have a phone no and want to save it in your own application then use this code it will move you to the "create contact" page of the default contact app.

      Intent addContactIntent = new Intent(Intent.ACTION_INSERT);
      addContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
      addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,phnno.getText().toString());
      startActivity(addContactIntent);
    
    0 讨论(0)
提交回复
热议问题