如何获取电话号码?
我正在尝试将用户选择的电话号码放入编辑文本中。我有一个按钮 :-
contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,
Phone.CONTENT_URI);
startActivityForResult(intent, 0);
}
});
和下面的功能 :
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case 0:
if (resultCode == Activity.RESULT_OK) {
Cursor c = getContentResolver().query(Phone.CONTENT_URI, null,
null, null, null);
c.moveToFirst();
String phone = c.getString(c.getColumnIndexOrThrow(Phone.NUMBER));
phone = phone.replace("-", "");
Log.v("getting phone number", "Phone Number: " + phone);
txtPhoneNo.setText(phone);
}
break;
}
}
我得到了最后一次联系的电话号码。我如何获取所选的电话号码?
I'm trying to put in an edittext the phone number that was selected by user. I have a button :-
contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,
Phone.CONTENT_URI);
startActivityForResult(intent, 0);
}
});
and the function below :
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case 0:
if (resultCode == Activity.RESULT_OK) {
Cursor c = getContentResolver().query(Phone.CONTENT_URI, null,
null, null, null);
c.moveToFirst();
String phone = c.getString(c.getColumnIndexOrThrow(Phone.NUMBER));
phone = phone.replace("-", "");
Log.v("getting phone number", "Phone Number: " + phone);
txtPhoneNo.setText(phone);
}
break;
}
}
and I got the phone number of last contact. How can I take the phone number that was selected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
做类似的事情:
Do something like:
看看这段代码!
从联系人屏幕返回后,
Have a look at this code!
after returning from contacts screen,