当前位置:首页 » 安卓系统 » android仿通讯录

android仿通讯录

发布时间: 2023-08-19 15:42:26

A. Android编程,根据姓名获得手机通讯录中的电话号码

java">importcn.teachcourse.R;

/**
*[email protected]/5/5.
*/
{
privatestaticfinalStringTAG=PhoneNameActivity.class.getSimpleName();
privateEditTextet;

publicstaticvoidstart(Contextcontext){
start(context,null);
}

publicstaticvoidstart(Contextcontext,Intentextras){
Intentintent=newIntent();
intent.setClass(context,PhoneNameActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|Intent.FLAG_ACTIVITY_SINGLE_TOP);
if(extras!=null){
intent.putExtras(extras);
}
context.startActivity(intent);
}

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_name);
et=(EditText)this.findViewById(R.id.mobile);
}

publicvoidgetTelClick(Viewview){
Stringname=et.getText().toString().trim();
number(name);
}

/**
*通过输入获取电话号码
*/
publicvoidnumber(Stringname){
//使用ContentResolver查找联系人数据
Cursorcursor=getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
//遍历查询结果,找到所需号码
while(cursor.moveToNext()){
//获取联系人ID
StringcontactId=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
//获取联系人的名字
StringcontactName=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
if(name.equals(contactName)){
//使用ContentResolver查找联系人的电话号码
Cursorphone=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"="+contactId,null,null);
if(phone.moveToNext()){
StringphoneNumber=phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(this,phoneNumber+"TeachCourse——blog。。。",Toast.LENGTH_SHORT).show();
Log.d(TAG,"电话:"+phoneNumber);
break;
}

}
}
}
}

1、修改getTelClick()方法

2、修改Toast面包屑提示

3、修改获取联系人名字方法

4、位置稍微调整

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:645
制作脚本网站 发布:2025-10-20 08:17:34 浏览:936
python中的init方法 发布:2025-10-20 08:17:33 浏览:632
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:821
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:731
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1066
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:299
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:160
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:852
python股票数据获取 发布:2025-10-20 07:39:44 浏览:763