文章标题
来源:互联网 发布:手机图片搜索软件 编辑:程序博客网 时间:2024/06/07 11:54
这是我个人实现的一些小技术`
public class ContactsActivity extends AppCompatActivity {
private EditText editText;
@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_contacts); initViews();}private void initViews() { editText = (EditText) findViewById(R.id.et_telPhone);}public void show(View view){ //跳转到通讯录界面 Uri uri = Uri.parse("content://contacts/people"); Intent intent = new Intent(Intent.ACTION_PICK, uri); startActivityForResult(intent, 0x101);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 0x101){ if (data == null){ return; } Uri uri = data.getData(); String[] strings = getPhoneContacts(uri); editText.setText(strings[0] + "\t" + strings[1]); }}private String[] getPhoneContacts(Uri uri){ String[] contact = new String[2]; ContentResolver cr = getContentResolver(); //取得电话本中开始一项的光标 Cursor cursor=cr.query(uri,null,null,null,null); if(cursor!=null) { cursor.moveToFirst(); //取得联系人姓名 int nameFieldColumnIndex=cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); contact[0]=cursor.getString(nameFieldColumnIndex); //取得电话号码 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); if(phone != null){ phone.moveToFirst(); contact[1] = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); } phone.close(); cursor.close(); } else { return null; } return contact;}
}
`
`public class MainActivity extends ListActivity {
private List<String> datas = new ArrayList<>();private ContentResolver cr;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initViews();}private void initViews() { cr = getContentResolver(); //获取短信的cureor对象 (content://sms/inbox短信内容提供者的uri) Cursor cursor = cr.query(Uri.parse("content://sms/inbox"),null,null,null,null); while (cursor.moveToNext()){ //body 为短信表的内容字段 datas.add(cursor.getString(cursor.getColumnIndex("body"))); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,datas); setListAdapter(adapter);}
}
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- Opencv2系列学习笔记2_2(图像的其它操作)
- 【模板】【字符串】KMP算法
- ac自动机详解与模板
- python使用问题积累
- php中多个站点配置方法
- 文章标题
- 【Leetcode】227. Basic Calculator II
- STM32 控制74HC595 驱动点阵 文字能移动
- 《Head first设计模式》学习笔记 – 命令模式
- Spring Cloud系列三 之 Hystrix断路器
- 进程、线程与处理器的调度
- Session知识概念
- java中静态代码块的用法static用法详解
- Android系统下的蓝牙协议