- 浏览: 49613 次
- 性别:
- 来自: 苏州
文章分类
最新评论
实例1:
android 中获取联系人
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while(cursor.moveToNext()){
//get name
int nameFiledColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = cursor.getString(nameFiledColumnIndex);
String[] PHONES_PROJECTION = new String[] { "_id","display_name","data1","data3"};//
String contactId = cursor.getString(cursor.getColumnIndex(PhoneLookup._ID));
Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PHONES_PROJECTION,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null);
//name type ..
while(phone.moveToNext()) {
int i = phone.getInt(0);
String str = phone.getString(1);
str = phone.getString(2);
str = phone.getString(3);
}
phone.close();
//addr
Cursor addrCur = cr.query(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI ,
new String[]{"_id","data1","data2","data3"}, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId , null, null);
while(addrCur.moveToNext()) {
int i = addrCur.getInt(0);
String str = addrCur.getString(1);
str = addrCur.getString(2);
str = addrCur.getString(3);
}
addrCur.close();
//email
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI ,
new String[]{"_id","data1","data2","data3"}, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId , null, null);
while(emailCur.moveToNext()) {
int i = emailCur.getInt(0);
String str = emailCur.getString(1);
str = emailCur.getString(2);
str = emailCur.getString(3);
}
emailCur.close();
}
cursor.close();
android中获取通话记录
String str = "";
int type;
long callTime;
Date date;
String time= "";
ContentResolver cr = getContentResolver();
final Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER,CallLog.Calls.CACHED_NAME,CallLog.Calls.TYPE, CallLog.Calls.DATE}, null, null,CallLog.Calls.DEFAULT_SORT_ORDER);
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
str = cursor.getString(0);
str = cursor.getString(1);
type = cursor.getInt(2);
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = new Date(Long.parseLong(cursor.getString(3)));
time = sfd.format(date);
}
实例2:
Andorid1.5及其以前的项目放到Android2.0上时,如果代码中有
import android.provider.Contacts;
Eclipse会提示“建议不使用”,那是因为在Android2.0中,联系人api发生了变化,需要使用ContactsContract。
直接看下面一个最简单的例子,读取联系人的姓名和电话号码:
读取联系人的名字很简单,但是在读取电话号码时,就需要先去的联系人的ID,然后在通过ID去查找电话号码!一个联系人可能存在多个电话号码!
//得到ContentResolver对象
ContentResolver cr = getContentResolver();
//取得电话本中开始一项的光标
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext())
{
// 取得联系人名字
int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String name = cursor.getString(nameFieldColumnIndex);
string += (name);
// 取得联系人ID
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
+ contactId, null, null);
// 取得电话号码(可能存在多个号码)
while (phone.moveToNext())
{
String strPhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
string += (":" + strPhoneNumber);
}
string += "\n";
phone.close();
}
cursor.close();
实例3:
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class PhoneBook extends Activity {
/*声明四个UI变量与一个常数作为Activity接收回传值用*/
private TextView mTextView01;
private Button mButton01;
private EditText mEditText01;
private EditText mEditText02;
private static final int PICK_CONTACT_SUBACTIVITY = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*透过findViewById建构子来建构一个TextView,两个EditText,一个Button对象**/
mTextView01 = (TextView)findViewById(R.id.myTextView1);
mEditText01 = (EditText)findViewById(R.id.myEditText01);
mEditText02 = (EditText)findViewById(R.id.myEditText02);
mButton01 = (Button)findViewById(R.id.myButton1);
/*设定onClickListener 让使用者点选Button时搜寻联系人*/
mButton01.setOnClickListener(new Button.OnClickListener()
{
// @Override
public void onClick(View v)
{
// TODO Auto-generated method stub
/*建构Uri来取得联络人的资源位置*/
// Uri uri = Uri.parse("content://contacts/people/");
/*透过Intent来取得联络人数据并回传所选的值*/
//Intent intent = new Intent(Intent.ACTION_PICK, uri);
/*开启新的Activity并期望该Activity回传值*/
//startActivityForResult(intent, PICK_CONTACT_SUBACTIVITY);
startActivityForResult
(
new Intent(Intent.ACTION_PICK,
android.provider.ContactsContract.Contacts.CONTENT_URI),
PICK_CONTACT_SUBACTIVITY);
}
});
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
try
{
switch (requestCode)
{
case PICK_CONTACT_SUBACTIVITY:
final Uri uriRet = data.getData();
if(uriRet != null)
{
try
{
/* 必须要有android.permission.READ_CONTACTS权限 */
Cursor c = managedQuery(uriRet, null, null, null, null);
/*将Cursor移到资料最前端*/
c.moveToFirst();
/*取得联络人的姓名*/
String strName = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
/*将姓名写入EditText01中*/
mEditText01.setText(strName);
/*取得联络人的电话*/
int contactId = c.getInt(c.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phones = getContentResolver().query ( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null );
StringBuffer sb = new StringBuffer();
int typePhone, resType;
String numPhone;
if (phones.getCount() > 0)
{
phones.moveToFirst();
/* 2.0可以允许User设定多组电话号码,但本范例只捞一组电话号码作示范 */
typePhone = phones.getInt ( phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE) );
numPhone = phones.getString ( phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER) );
resType = ContactsContract.CommonDataKinds.Phone.getTypeLabelResource(typePhone);
sb.append(getString(resType) +": "+ numPhone +"\n");
/*将电话写入EditText02中*/
mEditText02.setText(numPhone);
}
else
{
sb.append("no Phone number found");
}
/*Toast是否读取到完整的电话种类与电话号码*/
Toast.makeText(this, sb.toString(), Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
/*将错误信息在TextView中显示*/
mTextView01.setText(e.toString());
e.printStackTrace();
}
}
break;
default: break;
}
}
catch(Exception e)
{
e.printStackTrace();
}
super.onActivityResult(requestCode, resultCode, data);
}
}
-------------------------
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">PhoneBook</string>
<string name="str_button1">搜索</string>
<string name="str_title">我的联系人</string>
<string name="str_name">姓名</string>
<string name="str_telephone">电话号码</string>
</resources>
-----------------------------
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/myTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_title"
android:layout_x="0px"
android:layout_y="0px"
>
</TextView>
<EditText
android:id="@+id/myEditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_name"
android:textSize="18sp"
android:layout_x="0px"
android:layout_y="22px"
>
</EditText>
<EditText
android:id="@+id/myEditText02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_telephone"
android:textSize="18sp"
android:layout_x="0px"
android:layout_y="82px"
>
</EditText>
<Button
android:id="@+id/myButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_button1"
android:layout_x="10px"
android:layout_y="142px"
>
</Button>
</AbsoluteLayout>
------------------------------------
AndroidManifest.xml
注意在</application>后要加上
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<!--取得读取通讯录的权限 -->
实例4:
package com.activity;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.widget.TextView;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.TextView01);
String columns[] = new String[] { People._ID, People.NAME,
People.NUMBER, People.PRIMARY_EMAIL_ID,
People.PRIMARY_ORGANIZATION_ID, People.PRIMARY_PHONE_ID,
People.DISPLAY_NAME,
People.IM_ACCOUNT, People.IM_HANDLE, People.PHONETIC_NAME,
People.TYPE };
Uri mContacts = People.CONTENT_URI;
Cursor cur = managedQuery(mContacts, columns, // 要返回的数据字段
null, // WHERE子句
null, // WHERE 子句的参数
People.NAME // Order-by子句
);
if (cur.moveToFirst()) {
Cursor newcur = null;
do {
// 获取字段的值
String name = cur.getString(cur.getColumnIndex(People.NAME));
String phoneNo = cur.getString(cur
.getColumnIndex(People.NUMBER));
String peopleId = cur.getString(cur.getColumnIndex(People._ID));
String[] PROJECTION = new String[] {
Contacts.ContactMethods._ID,
Contacts.ContactMethods.KIND,
Contacts.ContactMethods.DATA };
newcur = managedQuery(Contacts.ContactMethods.CONTENT_URI,
PROJECTION, Contacts.ContactMethods.PERSON_ID + "=\'"
+ cur.getLong(cur.getColumnIndex(People._ID))
+ "\'", null, null);
startManagingCursor(newcur);
String email = "";
if (newcur.moveToFirst()) {
while (newcur.moveToNext()) {
email = email+ newcur.getString(newcur.getColumnIndex(Contacts.ContactMethods.DATA));
}
}
tv.setText("name = " + name + " phoneNo = " + phoneNo
+ "email = " + email);
if (email != null && !"".equals(email)
&& email.trim().length() != 0) {
// 此处可以取到联系人邮件
}
} while (cur.moveToNext());
if (newcur != null) {
newcur.close();// 用完得关闭吧
}
}
if (cur != null)
cur.close(); // 用完得关闭吧
}
}
android 中获取联系人
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while(cursor.moveToNext()){
//get name
int nameFiledColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = cursor.getString(nameFiledColumnIndex);
String[] PHONES_PROJECTION = new String[] { "_id","display_name","data1","data3"};//
String contactId = cursor.getString(cursor.getColumnIndex(PhoneLookup._ID));
Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PHONES_PROJECTION,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null);
//name type ..
while(phone.moveToNext()) {
int i = phone.getInt(0);
String str = phone.getString(1);
str = phone.getString(2);
str = phone.getString(3);
}
phone.close();
//addr
Cursor addrCur = cr.query(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI ,
new String[]{"_id","data1","data2","data3"}, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId , null, null);
while(addrCur.moveToNext()) {
int i = addrCur.getInt(0);
String str = addrCur.getString(1);
str = addrCur.getString(2);
str = addrCur.getString(3);
}
addrCur.close();
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI ,
new String[]{"_id","data1","data2","data3"}, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId , null, null);
while(emailCur.moveToNext()) {
int i = emailCur.getInt(0);
String str = emailCur.getString(1);
str = emailCur.getString(2);
str = emailCur.getString(3);
}
emailCur.close();
}
cursor.close();
android中获取通话记录
String str = "";
int type;
long callTime;
Date date;
String time= "";
ContentResolver cr = getContentResolver();
final Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER,CallLog.Calls.CACHED_NAME,CallLog.Calls.TYPE, CallLog.Calls.DATE}, null, null,CallLog.Calls.DEFAULT_SORT_ORDER);
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
str = cursor.getString(0);
str = cursor.getString(1);
type = cursor.getInt(2);
SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date = new Date(Long.parseLong(cursor.getString(3)));
time = sfd.format(date);
}
实例2:
Andorid1.5及其以前的项目放到Android2.0上时,如果代码中有
import android.provider.Contacts;
Eclipse会提示“建议不使用”,那是因为在Android2.0中,联系人api发生了变化,需要使用ContactsContract。
直接看下面一个最简单的例子,读取联系人的姓名和电话号码:
读取联系人的名字很简单,但是在读取电话号码时,就需要先去的联系人的ID,然后在通过ID去查找电话号码!一个联系人可能存在多个电话号码!
//得到ContentResolver对象
ContentResolver cr = getContentResolver();
//取得电话本中开始一项的光标
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext())
{
// 取得联系人名字
int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String name = cursor.getString(nameFieldColumnIndex);
string += (name);
// 取得联系人ID
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
+ contactId, null, null);
// 取得电话号码(可能存在多个号码)
while (phone.moveToNext())
{
String strPhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
string += (":" + strPhoneNumber);
}
string += "\n";
phone.close();
}
cursor.close();
实例3:
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class PhoneBook extends Activity {
/*声明四个UI变量与一个常数作为Activity接收回传值用*/
private TextView mTextView01;
private Button mButton01;
private EditText mEditText01;
private EditText mEditText02;
private static final int PICK_CONTACT_SUBACTIVITY = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*透过findViewById建构子来建构一个TextView,两个EditText,一个Button对象**/
mTextView01 = (TextView)findViewById(R.id.myTextView1);
mEditText01 = (EditText)findViewById(R.id.myEditText01);
mEditText02 = (EditText)findViewById(R.id.myEditText02);
mButton01 = (Button)findViewById(R.id.myButton1);
/*设定onClickListener 让使用者点选Button时搜寻联系人*/
mButton01.setOnClickListener(new Button.OnClickListener()
{
// @Override
public void onClick(View v)
{
// TODO Auto-generated method stub
/*建构Uri来取得联络人的资源位置*/
// Uri uri = Uri.parse("content://contacts/people/");
/*透过Intent来取得联络人数据并回传所选的值*/
//Intent intent = new Intent(Intent.ACTION_PICK, uri);
/*开启新的Activity并期望该Activity回传值*/
//startActivityForResult(intent, PICK_CONTACT_SUBACTIVITY);
startActivityForResult
(
new Intent(Intent.ACTION_PICK,
android.provider.ContactsContract.Contacts.CONTENT_URI),
PICK_CONTACT_SUBACTIVITY);
}
});
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
try
{
switch (requestCode)
{
case PICK_CONTACT_SUBACTIVITY:
final Uri uriRet = data.getData();
if(uriRet != null)
{
try
{
/* 必须要有android.permission.READ_CONTACTS权限 */
Cursor c = managedQuery(uriRet, null, null, null, null);
/*将Cursor移到资料最前端*/
c.moveToFirst();
/*取得联络人的姓名*/
String strName = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
/*将姓名写入EditText01中*/
mEditText01.setText(strName);
/*取得联络人的电话*/
int contactId = c.getInt(c.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phones = getContentResolver().query ( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null );
StringBuffer sb = new StringBuffer();
int typePhone, resType;
String numPhone;
if (phones.getCount() > 0)
{
phones.moveToFirst();
/* 2.0可以允许User设定多组电话号码,但本范例只捞一组电话号码作示范 */
typePhone = phones.getInt ( phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE) );
numPhone = phones.getString ( phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER) );
resType = ContactsContract.CommonDataKinds.Phone.getTypeLabelResource(typePhone);
sb.append(getString(resType) +": "+ numPhone +"\n");
/*将电话写入EditText02中*/
mEditText02.setText(numPhone);
}
else
{
sb.append("no Phone number found");
}
/*Toast是否读取到完整的电话种类与电话号码*/
Toast.makeText(this, sb.toString(), Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
/*将错误信息在TextView中显示*/
mTextView01.setText(e.toString());
e.printStackTrace();
}
}
break;
default: break;
}
}
catch(Exception e)
{
e.printStackTrace();
}
super.onActivityResult(requestCode, resultCode, data);
}
}
-------------------------
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">PhoneBook</string>
<string name="str_button1">搜索</string>
<string name="str_title">我的联系人</string>
<string name="str_name">姓名</string>
<string name="str_telephone">电话号码</string>
</resources>
-----------------------------
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/myTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_title"
android:layout_x="0px"
android:layout_y="0px"
>
</TextView>
<EditText
android:id="@+id/myEditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_name"
android:textSize="18sp"
android:layout_x="0px"
android:layout_y="22px"
>
</EditText>
<EditText
android:id="@+id/myEditText02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_telephone"
android:textSize="18sp"
android:layout_x="0px"
android:layout_y="82px"
>
</EditText>
<Button
android:id="@+id/myButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_button1"
android:layout_x="10px"
android:layout_y="142px"
>
</Button>
</AbsoluteLayout>
------------------------------------
AndroidManifest.xml
注意在</application>后要加上
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<!--取得读取通讯录的权限 -->
实例4:
package com.activity;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.widget.TextView;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.TextView01);
String columns[] = new String[] { People._ID, People.NAME,
People.NUMBER, People.PRIMARY_EMAIL_ID,
People.PRIMARY_ORGANIZATION_ID, People.PRIMARY_PHONE_ID,
People.DISPLAY_NAME,
People.IM_ACCOUNT, People.IM_HANDLE, People.PHONETIC_NAME,
People.TYPE };
Uri mContacts = People.CONTENT_URI;
Cursor cur = managedQuery(mContacts, columns, // 要返回的数据字段
null, // WHERE子句
null, // WHERE 子句的参数
People.NAME // Order-by子句
);
if (cur.moveToFirst()) {
Cursor newcur = null;
do {
// 获取字段的值
String name = cur.getString(cur.getColumnIndex(People.NAME));
String phoneNo = cur.getString(cur
.getColumnIndex(People.NUMBER));
String peopleId = cur.getString(cur.getColumnIndex(People._ID));
String[] PROJECTION = new String[] {
Contacts.ContactMethods._ID,
Contacts.ContactMethods.KIND,
Contacts.ContactMethods.DATA };
newcur = managedQuery(Contacts.ContactMethods.CONTENT_URI,
PROJECTION, Contacts.ContactMethods.PERSON_ID + "=\'"
+ cur.getLong(cur.getColumnIndex(People._ID))
+ "\'", null, null);
startManagingCursor(newcur);
String email = "";
if (newcur.moveToFirst()) {
while (newcur.moveToNext()) {
email = email+ newcur.getString(newcur.getColumnIndex(Contacts.ContactMethods.DATA));
}
}
tv.setText("name = " + name + " phoneNo = " + phoneNo
+ "email = " + email);
if (email != null && !"".equals(email)
&& email.trim().length() != 0) {
// 此处可以取到联系人邮件
}
} while (cur.moveToNext());
if (newcur != null) {
newcur.close();// 用完得关闭吧
}
}
if (cur != null)
cur.close(); // 用完得关闭吧
}
}
相关推荐
在Android 2.0及更高版本中,由于SDK对联系人数据的访问方式进行了更新,开发者需要使用新的API来读取和操作联系人信息。本文将详细介绍如何使用`ContactsContract`类来实现这一功能。 在Android 2.0之前,开发人员...
在Android中,联系人通常存储在Content Provider中,由`ContactsContract`类提供接口进行访问和操作。短信则通过`SmsProvider`来管理,而通话记录则由`CallLog` Content Provider负责。自Android 4.4(KitKat)版本...
在Android平台上,开发人员可以利用系统的API来读取用户的联系人数据。这通常涉及到权限管理、ContentResolver的使用以及Cursor的遍历等关键知识点。以下是对这个"android读取系统联系人"主题的详细讲解: 1. **...
在Android应用开发中,通话记录源码是一个典型的实践案例,尤其对于毕业生来说,这是一个很好的学习和研究项目。本文将深入探讨Android通话记录源码的相关知识点,帮助你理解如何在Android平台上构建一个能够读取、...
在Android中,访问通话记录需要获取相应的权限。在`AndroidManifest.xml`文件中,你需要添加以下权限: ```xml <uses-permission android:name="android.permission.READ_CALL_LOG" /> <uses-permission android...
通过阅读和分析这些文件,开发者可以更深入地理解Android中如何操作联系人数据以及实现拨打电话的功能。 总结来说,这个项目涉及了Android的权限管理、ContentResolver、ContactsContract API、数据查询、UI交互...
在AndroidManifest.xml文件中,需要声明访问通话记录的权限,分别是读取和写入权限: ```xml <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android....
在Android平台上,获取和操作设备上...这个示例项目是一个很好的起点,可以帮助开发者理解和掌握Android中访问和展示联系人数据的基本方法。记得在实际项目中进行适当的错误处理和优化,以提供更稳定和流畅的用户体验。
在实际应用中,我们可能还需要对通话记录进行更复杂的操作,例如筛选特定联系人的通话记录、统计通话时长等。这些可以通过调整查询条件或对查询结果进行处理来实现。 最后,`CallLogDemo`这个项目名称暗示了这是一...
Android提供了VCard库来解析和生成VCard文件,我们可以通过VCardReader或者VCardWriter来读取或写入联系人信息。VCard数据在接收到OBEX GET请求响应后会被解析,然后可以存储到Android系统的联系人数据库中。 在...
android 8.1系统蓝牙连接,获取通讯录及通话记录、蓝牙电话等相关代码逻辑梳理
这个“NPOI2.0官方版本”是该库的一个重要更新,允许开发者在不依赖Microsoft Office软件环境的情况下,进行文档的读取和写入操作。NPOI构建于.NET框架之上,因此它适用于基于.NET的应用程序,无论是Windows、Linux...
在Android系统中,默认的浏览器应用通常具有读取联系人的权限,以便于用户可以通过输入姓名或电话号码快速填充网页表单。然而,这种行为可能会引起隐私方面的顾虑,有些用户可能不希望他们的联系人数据被浏览器访问...
在《Android2.0游戏开发实战宝典源代码》中,我们可以深入学习和理解如何利用Android 2.0 SDK进行游戏开发。这份源代码集合涵盖了多个游戏开发的关键知识点,包括但不限于以下几个方面: 1. **Android SDK与环境...
InfluxDB 2.0 版本+Telegraf 硬件监控系统教程 ...本教程提供了一个基于 InfluxDB 2.0 版本和 Telegraf 的硬件监控系统的构建指南,涵盖了 InfluxDB 和 Telegraf 的安装、配置、数据采集和处理等方面的知识点。
- 创建和读取XLS和XLSX格式的工作簿:NPOI允许开发者创建新的Excel工作簿,以及读取和修改现有的XLS和XLSX文件。这两种格式分别对应Excel的早期版本和基于Open XML标准的新版格式。 - 工作表操作:包括添加、删除...
在描述中提到的"ASP.NET 2.0 读取配置文件[INI]",虽然通常ASP.NET使用XML格式的Web.config文件,但这里指的是读取传统的INI文件,这是一种简单文本格式的配置文件,广泛应用于早期的Windows系统和某些跨平台的应用...
本文将详细介绍如何在Android中实现Excel文件的读取与写入。 首先,Android系统本身并不直接支持Excel文件的操作,因此我们需要引入第三方库来实现这一功能。常用的库有Apache POI,这是一个用于处理Microsoft ...
总之,MySQL.Data.dll .net2.0版本是.NET开发者连接和操作MySQL数据库的重要工具,它提供了丰富的功能和接口,简化了数据库交互过程,提高了开发效率。在实际开发中,熟练掌握其用法对于构建基于.NET Framework 2.0...