android 点滴积累
2012-08-02 22:45
274 查看
1、android程序查詢包含"*" "#"的號碼時出錯的解決辦法
2、android通过查询电话号码获取联系人头像
/**
* @author 张兴业
* 邮箱:xy-zhang#163.com
* android开发进阶群:278401545
*
*/
代碼錯誤提示: E/AndroidRuntime(1145): Caused by: android.database.sqlite.SQLiteException: near "*": syntax error: , while compiling: SELECT numbertype, new, duration, _id, numberlabel, name, number, type, date FROM calls WHERE (number = **9) ORDER BY date desc 解決: strQuery = "number = " + strQueryNumber; callLogCursor = TApplication.nowTApplication.getContentResolver() .query(CallLog.Calls.CONTENT_URI, null, strQuery, null, "date desc"); 查詢代碼改成: strQuery = "number = " + "'strQueryNumber'"; callLogCursor = TApplication.nowTApplication.getContentResolver() .query(CallLog.Calls.CONTENT_URI, null, strQuery, null, "date desc"); 總結:因為"*"為數據庫里的關鍵字(未經證實),所有查找是會報語法錯誤,只需要拼接字符串,把"*"改成非關鍵字即可
2、android通过查询电话号码获取联系人头像
// 取得Intent中的頭像 ivShowImage = (ImageView) findViewById(R.id.call_log_detail_contact_img); //通话电话号码获取头像uri Uri uriNumber2Contacts = Uri .parse("content://com.android.contacts/" + "data/phones/filter/" + strPhoneNumber); Cursor cursorCantacts = SApplication.nowSApplication .getContentResolver().query(uriNumber2Contacts, null, null, null, null); if (cursorCantacts.getCount() > 0) { //若游标不为0则说明有头像,游标指向第一条记录 cursorCantacts.moveToFirst(); Long contactID = cursorCantacts.getLong(cursorCantacts .getColumnIndex("contact_id")); Uri uri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, contactID); InputStream input = ContactsContract.Contacts .openContactPhotoInputStream( SApplication.nowSApplication .getContentResolver(), uri); btContactImage = BitmapFactory.decodeStream(input); Log.i("info", "bt======" + btContactImage); ivShowImage.setImageBitmap(btContactImage); } else {//么有头像设置默认头像 ivShowImage .setImageResource(R.drawable.call_log_contact_image2); }
/**
* @author 张兴业
* 邮箱:xy-zhang#163.com
* android开发进阶群:278401545
*
*/
相关文章推荐
- 【android】android 开发错误点滴积累5月--Asset资源管理
- Android初学点滴积累(操作篇)
- 三星平台 android audio 架构探讨点滴积累之一
- 【android】android 开发错误点滴积累5月--Asset资源管理
- 三星平台 android audio 架构探讨点滴积累之二
- Android开发点滴积累
- android 点滴积累
- android 开发错误点滴积累--Asset资源管理
- android 点滴积累
- android 开发错误点滴积累--Asset资源管理
- android 开发错误点滴积累--Asset资源管理
- Android初学点滴积累(操作篇)
- 三星平台 android audio 架构探讨点滴积累之一
- Android点滴积累系列--资源overlay机制(转)
- android点滴积累
- android 积累
- android点滴之NFC 程序设计
- Android 学习技巧积累
- 点滴积累1
- Android 开发中的日常积累