Can you please tell me how to launch the Add Contact' activity in android? Thank you.
你能告诉我如何在android中启动Add Contact'活动吗?谢谢。
8 个解决方案
#1
9
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.
根据评论,请查看下面的vickey答案,以获得相应的解决方案。
#2
59
API Level 5 and above solution
API Level 5及以上解决方案
// Add listener so your activity gets called back upon completion of action,
// in this case with ability to get handle to newly added contact
myActivity.addActivityListener(someActivityListener);
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
// Just two examples of information you can send to pre-fill out data for the
// user. See android.provider.ContactsContract.Intents.Insert for the complete
// list.
intent.putExtra(ContactsContract.Intents.Insert.NAME, "some Contact Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "some Phone Number");
// Send with it a unique request code, so when you get called back, you can
// check to make sure it is from the intent you launched (ideally should be
// some public static final so receiver can check against it)
int PICK_CONTACT = 100;
myActivity.startActivityForResult(intent, PICK_CONTACT);
#3
42
These two lines do the trick:
这两行可以解决问题:
Intent intent = new Intent(Intent.ACTION_INSERT,
ContactsContract.Contacts.CONTENT_URI);
startActivity(intent);
#4
14
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)
#5
9
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);
#6
7
I was also trying to do this. I was able to launch the activity using Android 2.2. I haven't tried using/testing this in other SDK versions though.
我也试图这样做。我能够使用Android 2.2启动活动。我没有尝试过在其他SDK版本中使用/测试它。
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse("tel:" + currentNum.getText())); //currentNum is my TextView, you can replace it with the number directly such as Uri.parse("tel:1293827")
intent.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true); //skips the dialog box that asks the user to confirm creation of contacts
startActivity(intent);
Hope this might help.
希望这可能有所帮助。
#7
5
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)
.
只需查看Android的DialpadFragment类源代码,搜索方法getAddToContactIntent(String digits)。
But as the People class is deprecated in api 10 you may want to use this line instead:
但是由于在api 10中不推荐使用People类,您可能希望使用此行代替:
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
#8
1
Intent localintent = new Intent("android.intent.action.INSERT",ContactsContract.Contacts.CONTENT_URI);
localintent.putExtra("phone", phoneNumber);
startActivity(localintent);
#1
9
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.
根据评论,请查看下面的vickey答案,以获得相应的解决方案。
#2
59
API Level 5 and above solution
API Level 5及以上解决方案
// Add listener so your activity gets called back upon completion of action,
// in this case with ability to get handle to newly added contact
myActivity.addActivityListener(someActivityListener);
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
// Just two examples of information you can send to pre-fill out data for the
// user. See android.provider.ContactsContract.Intents.Insert for the complete
// list.
intent.putExtra(ContactsContract.Intents.Insert.NAME, "some Contact Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "some Phone Number");
// Send with it a unique request code, so when you get called back, you can
// check to make sure it is from the intent you launched (ideally should be
// some public static final so receiver can check against it)
int PICK_CONTACT = 100;
myActivity.startActivityForResult(intent, PICK_CONTACT);
#3
42
These two lines do the trick:
这两行可以解决问题:
Intent intent = new Intent(Intent.ACTION_INSERT,
ContactsContract.Contacts.CONTENT_URI);
startActivity(intent);
#4
14
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)
#5
9
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);
#6
7
I was also trying to do this. I was able to launch the activity using Android 2.2. I haven't tried using/testing this in other SDK versions though.
我也试图这样做。我能够使用Android 2.2启动活动。我没有尝试过在其他SDK版本中使用/测试它。
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse("tel:" + currentNum.getText())); //currentNum is my TextView, you can replace it with the number directly such as Uri.parse("tel:1293827")
intent.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true); //skips the dialog box that asks the user to confirm creation of contacts
startActivity(intent);
Hope this might help.
希望这可能有所帮助。
#7
5
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)
.
只需查看Android的DialpadFragment类源代码,搜索方法getAddToContactIntent(String digits)。
But as the People class is deprecated in api 10 you may want to use this line instead:
但是由于在api 10中不推荐使用People类,您可能希望使用此行代替:
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
#8
1
Intent localintent = new Intent("android.intent.action.INSERT",ContactsContract.Contacts.CONTENT_URI);
localintent.putExtra("phone", phoneNumber);
startActivity(localintent);