手机软件功能开发(8)
时间:2025-04-23
时间:2025-04-23
Android手机系统的手机功能开发例子
* 查询,peopleName==*查询全部 */ private void queryContacts(String peopleName) {
//查询联系人
StringBuilder buffer = null;
String[] keyword = null;
if (peopleName != null) {
buffer = new StringBuilder();
buffer.append("UPPER(");
buffer.append(contacts_lable[1]);
buffer.append(") GLOB ?");
keyword = new String[] { peopleName.toString().toUpperCase() + "*" }; }
Cursor cursor = getContentResolver().query(phonesUri
, contacts_lable
, buffer == null ? null : buffer.toString()//查询条件 , keyword//查询条件 , People.DEFAULT_SORT_ORDER);//顺序 contactslist = null; contactslist = new ArrayList<Map<String, Object>>(); //取出查询结果 if (cursor.moveToFirst()) { String id = null; String name = null; String phoneNumber = null; while(cursor.getPosition()!=cursor.getCount()){ id = cursor.getString(cursor.getColumnIndex(contacts_lable[0])); name = cursor.getString(cursor.getColumnIndex(contacts_lable[1])); phoneNumber = cursor.getString(cursor.getColumnIndex(contacts_lable[2])); Map<String, Object> map = new HashMap<String, Object>(); map.put(contacts_lable[0], id); map.put(contacts_lable[1], name); map.put(contacts_lable[2], phoneNumber); contactslist.add(map); cursor.moveToNext(); } }else{ Toast.makeText(this, "无联系人信息!", Toast.LENGTH_LONG).show();