gpt4 book ai didi

java - 如何在 Android 中添加联系人,如 skype, native 联系人应用程序中的 whatsapp?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:05:36 26 4
gpt4 key购买 nike

我正在创建联系人应用程序,但想从我的应用程序(如 Skype 或 WhatsApp)在 native android 联系人应用程序中添加联系人。我需要扩展哪个类来实现此功能?

这正是我想要创建的图片:

enter image description here

最佳答案

好的,如果我明白你在找什么。您想使用 native Android 联系人列表。如果是这样,那么以下是步骤:

  1. 激发结果的 Intent
  2. 接收结果 Intent 以查找 Intent 结果代码。
  3. 返回带有联系信息的光标
  4. 设置值。

一个简短的例子。火意

Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);

//Receive the result
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case CONTACT_PICKER_RESULT:
//deal with the resulting contact info. I built a separate util class for that.. but here is an example of the code.
String[] projection = { ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Email.ADDRESS };
Uri result = data.getData();
String id = result.getLastPathSegment();
ContentResolver contentResolver = getActivity().getContentResolver();

//return cursor
cur = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
ContactsContract.CommonDataKinds.Phone._ID + " like \"" + idUser + "%\"", null, null);
//Use the cursor to return what you need.
}
}

这是一个调用游标的例子。请在 android 文档中阅读更多关于接触光标的信息。

email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));

关于java - 如何在 Android 中添加联系人,如 skype, native 联系人应用程序中的 whatsapp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24250980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com