由网友(神啊,赐予我力量吧)分享简介:我是新来的机器人,我需要让我接触的细节,但细节只包括3 I am new to android ,I need to get the details of my contacts, but the details include only 3 联系人姓名Contact name联系电话以及电子邮件ID 当我pr...
我是新来的机器人,我需要让我接触的细节,但细节只包括3
I am new to android ,I need to get the details of my contacts, but the details include only 3
联系人姓名
Contact name
联系电话以及
电子邮件ID
当我preSS一个按钮,它会告诉我的所有联系人这3细节
when I press a Button it will show these 3 details of my all contacts
我使用的Android 2.1埃克莱尔版本。任何解决方案?
I am using android Eclair version 2.1. Any solution ?
推荐答案
通过code以下,你可以做到这一点 -
By below code you can do that -
public void doLaunchContactPicker(View view) {
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK) {
switch (requestCode)
{
case CONTACT_PICKER_RESULT:
Cursor cursor = null;
String email = "", name = "";
try {
Uri result = data.getData();
Log.v(DEBUG_TAG, "Got a contact result: " + result.toString());
// get the contact id from the Uri
String id = result.getLastPathSegment();
// query for everything email
cursor = getContentResolver().query(Email.CONTENT_URI, null, Email.CONTACT_ID + "=?", new String[] { id }, null);
int nameId = cursor.getColumnIndex(Contacts.DISPLAY_NAME);
int emailIdx = cursor.getColumnIndex(Email.DATA);
// let's just get the first email
if (cursor.moveToFirst()) {
email = cursor.getString(emailIdx);
name = cursor.getString(nameId);
Log.v(DEBUG_TAG, "Got email: " + email);
} else {
Log.w(DEBUG_TAG, "No results");
}
} catch (Exception e) {
Log.e(DEBUG_TAG, "Failed to get email data", e);
} finally {
if (cursor != null) {
cursor.close();
}
EditText emailEntry = (EditText) findViewById(R.id.editTextv);
EditText personEntry = (EditText) findViewById(R.id.person);
emailEntry.setText(email);
personEntry.setText(name);
if (email.length() == 0 && name.length() == 0)
{
Toast.makeText(this, "No Email for Selected Contact",Toast.LENGTH_LONG).show();
}
}
break;
}
} else {
Log.w(DEBUG_TAG, "Warning: activity result not ok");
}
}
和,也请参阅以下链接 -
And, also refer these links -
获取联系方式
如何阅读联系人
得到的所有联系方式
不要忘记添加所需的权限 -
Don't forget to add the required permission -
<uses-permission android:name="android.permission.READ_CONTACTS"/>
在的AndroidManifest.xml
文件。而且,只需修改此code与您的需求。
in your AndroidManifest.xml
file. And, Just modify this code with your needs.
相关推荐
最新文章