gpt4 book ai didi

android - 加载并显示联系android

转载 作者:行者123 更新时间:2023-11-30 01:50:21 26 4
gpt4 key购买 nike

我想问问是否有人可以帮助我。我想将联系人从我在 android 中的联系人列表加载到我的 TextView 或 ListView 中。我有一个按钮,上面写着“添加联系人”,按钮名称是 addcontacts。我有一个 ContactView Activity ,我已经在其中设置了所有内容。我已经编写了一些代码,但这不是我想要做的。

public class ContactView extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_view);
Button insert = (Button) findViewById(R.id.addcontact);
insert.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
insert();
}
});
}

public void insert() {
Intent intent = new Intent(
ContactsContract.Intents.SHOW_OR_CREATE_CONTACT,
ContactsContract.Contacts.CONTENT_URI);
intent.setData(Uri.parse("tel:011-9999999"));//specify your number here
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, "Google");
intent.putExtra(ContactsContract.Intents.Insert.POSTAL,
"Addresse, Street Name, State/Country");
startActivity(intent);
Toast.makeText(this, "Lade Ansicht", Toast.LENGTH_SHORT).show();
}

public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.contact_menu, menu);
return true;
}

这是我已经拥有的。这让我可以在我的应用程序中创建联系人,但这不是应该的方式,因为我想显示已经创建的联系人。当我让用户在应用程序中创建它们时,他们将拥有双重联系人。

谁能帮我从现有的联系人中加载它们并以我的方式显示它们??

最佳答案

您可以通过以下代码从您的电话联系人中获取电话号码和姓名

Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
String Name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)
String Number=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

}

关于android - 加载并显示联系android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33150266/

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