- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用一个应用程序,在此我必须在单击按钮并从电话联系人中选择一个联系人时搜索联系人。最后我想将它设置为 edittext
。我可以从电话联系人中搜索联系人,但我无法从电话联系人中获取联系人。
Activity :
searchBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent,1);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==RESULT_OK){
Uri contactData = data.getData();
Cursor cursor = managedQuery(contactData, null, null, null, null);
cursor.moveToFirst();
String number = cursor.getString(cursor.getColumnIndexOrThrow
(ContactsContract.CommonDataKinds.Phone.NUMBER));
//contactName.setText(name);
ephoneNumber.setText(number);
//contactEmail.setText(email);
}
}
最佳答案
首先像这样为 StartActivityForResult 设置 Intent
private void pickContact() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
然后处理 native 联系人应用程序的 Intent 携带的结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request it is that we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
// We only need the NUMBER column, because there will be only one row in the result
String[] projection = {Phone.NUMBER};
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
// Do something with the phone number...
}
}
}
查看另一个引用链接
关于android - 搜索联系人并从 android 中的电话联系人中获取联系电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22066142/
我正在尝试连接到 webapi,该位置在我的 js jquery 文件中看起来像这样。 example.com/?var=input 有没有比 ajax 调用更简单的方法? 最佳答案 我会为此使用 A
我编写了 PHP 代码,它连接到 MYSQL 来查找信息,将其发送到 API,并获取响应以写回到新表中。 有时它工作得很好,有时则不然。如果没有,它会给我这个错误 You have an error
每个子列表都意味着他们是 friend ,现在我想创建一个函数 def is_connected_via_friendships_with 来检查他们是否通过与另一个人的友谊联系在一起。例如,玛丽是卢
我正在尝试将 Cassandra 与 Hector 联系起来: public class Main { public static void main(String[] args) {
我正在使用 mautic API 进行电子邮件列表和电子邮件发送。我正在尝试使用 mautic API auth2.0 获取所有电子邮件列表我正在正确获取访问 token ,但是当我像这样调用电子邮件
我已经与Windows Forms Application进行了简单的聊天。我正在使用套接字,当我尝试连接本地IP时,一切正常,并且可以在本地发送消息。 但是,当我尝试使用外部IP连接到我的 frie
我正在开发我的第一个 GWT 应用程序,它将使用来自 RESTful API 的数据。 我试图找出构建整个应用程序的最佳方法。 GWT 客户端应该与 Java 服务器端联系,然后再联系 API,还是
我对线程中的异常处理有疑问。我有一个简单的 WCF 服务,它需要一些字节作为输入。此 WCF 服务是从控制台应用程序调用的。 方法片段(我的方法) try { _service.ImportBy
我正在尝试编写一个基本的卷应用程序。由于我是用 Ruby 编写的,因此我不想扩展 C 库或使用 ffi ,而是尝试使用 ruby-dbus 编写它,我使用 Address 获得了 /org/pulse
我知道在 CRM 2011 中您无法将联系人转换为潜在客户。在 CRM 2013 中是否可行。 简单来说,我创建了一个联系人并将其分组到一个帐户中。我想将此联系人转换为潜在客户,以便我可以输入销售信息
如何在我的网站页面上添加共享按钮,我们可以使用以下代码在移动 HTML 页面上添加发送短信: title 如何在 Viber、Watsapp 等分享中使用此示例 最佳答案 仅限 HTML 页面。我通常
我想了解 Azure 在门户中创建 Web 应用程序机器人时会做什么。 An Azure Bot Service Bot deployed to an Azure App Service Web Ap
我目前正在构建 Android 4.4。与 seek-for-android在我的 Nexus 5 上获得 UICC 支持。 到目前为止还没有成功。我确实应用了提到的所有补丁 here和 here .
我开发了一个用于农村 Activity 和监控/管理的应用程序。 我的应用程序在白天收集了大量数据,需要将其发送到云端进行处理和分析。在一个正常的 8 小时工作日中,它可以收集多达 2Gb 的数据(大
我编写了一个连接器来从 mysql 获取数据,当 iam 在路由内运行 Mysql 连接器时,它显示错误,并且浏览器正在运行到无限循环。 var express = require('express'
我最近有一个高级主题,mailchimp 的表单看起来非常酷。 我想知道我是否可以将样式用于我的 3 Field Based Contact 表单“REQUEST A CALL BACK”- 名称输入
我正在尝试将基本的 onClick 事件附加到设备中的联系人列表。联系人列表已正确生成。我的代码摘要如下: public class Contacts extends AppCompatActivit
我有一种方法可以根据 Active Directory 验证用户凭据。我想将此方法与 SSL 结合使用,但无法正常工作。 主要问题是我有一个在我们网络之外的服务器(它叫 DMZ 吗?)。从那里我想联系
我正准备在 symfony Doctrine 中开始一个项目,但我必须与多个数据库建立连接。其中之一是无法使用 ORM 映射的现有数据库 (SQL SERVER)。是否有可能将此数据库与另一个未在 D
尝试为 openstack USSURI 版本设置 Controller 节点时。我被要求将 Glance 服务设置为 VM 图像管理子服务。 根据要求:article (在 ubuntu 18.04
我是一名优秀的程序员,十分优秀!