让用户选择一个联系人并获取该联系人的手机号码
我试图让用户从他的联系人列表中选择一个联系人,以便我可以对该号码进行一些处理。我启动列表选择活动的代码是
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.Phones.CONTENT_URI);
startActivityForResult(contactPickerIntent, PICK_CONTACT);
,我的接收代码是,
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Set<String> keys = extras.keySet();
Iterator<String> iterate = keys.iterator();
while (iterate.hasNext()) {
String key = iterate.next();
Log.v(TAG, key + "[" + extras.get(key) + "]");
}
Uri result = data.getData();
Log.v(TAG, "Got a result: "
+ result.toString());
}
break;
}
}
但额外捆绑包中没有任何姓名或电话号码。如何获取用户选择的结果?
I'm trying to have a user pick a contact from his contacts list so that I can do some processing on that number. My code to launch the list-picking activity is
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.Phones.CONTENT_URI);
startActivityForResult(contactPickerIntent, PICK_CONTACT);
and my receiving code is
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Set<String> keys = extras.keySet();
Iterator<String> iterate = keys.iterator();
while (iterate.hasNext()) {
String key = iterate.next();
Log.v(TAG, key + "[" + extras.get(key) + "]");
}
Uri result = data.getData();
Log.v(TAG, "Got a result: "
+ result.toString());
}
break;
}
}
but the extras bundle does not have any names or phone numbers in it. How can I get the result of a user's selection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getData() 调用包含可在其上打开游标的 Uri。请尝试以下操作:
The getData() call contains the Uri that you can open a cursor on. Try the following: