使用联系人 API 时,SG SIII 和注 2 的 JB 更新异常

Posted

技术标签:

【中文标题】使用联系人 API 时,SG SIII 和注 2 的 JB 更新异常【英文标题】:Exception on SG SIII and Note 2 with JB update while using Contacts API 【发布时间】:2012-09-29 16:26:07 【问题描述】:

我正在开发一个使用 android Contacts API 的应用。 我的代码工作正常,但最近 Play Market Feedback 中开始出现新错误。 看起来这些错误只出现在 SGS3 和 Note2 上。

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.support.v4.content.ModernAsyncTask$3.done(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: android.database.sqlite.SQLiteException: near ":<phonenumber>": syntax error (code 1): , while compiling: SELECT times_contacted, contacts_status_updates.status AS contact_status, phonetic_name, phonetic_name_style, ((CASE WHEN raw_contact_linkpriority1 > 0 THEN link_type1||'|' ELSE '' END)||(CASE WHEN raw_contact_linkpriority2 > 0 THEN link_type2||'|' ELSE '' END)||(CASE WHEN raw_contact_linkpriority3 > 0 THEN link_type3||'|' ELSE '' END)||(CASE WHEN raw_contact_linkpriority4 > 0 THEN link_type4||'|' ELSE '' END)||(CASE WHEN raw_contact_linkpriority5 > 0 THEN link_type5 ELSE '' END)) AS link, is_user_profile, snippet, raw_contact_linkpriority4, lookup, raw_contact_linkpriority5, contacts_status_updates.status_icon AS contact_status_icon, sec_custom_vibration, last_time_contacted, _id, photo_uri, display_name_source, photo_thumb_uri, agg_presence.chat_capability AS contact_chat_capability, photo_id, send_to_voicemail, display_name_alt AS display_name_reverse, name_raw_contact_id, custom_ringtone, photo_file_id, has_phone_number, link_type5, link_type4, link_type3, link_type2, contacts_status_updates.status_label AS contact_status_label, link_type1, raw_contact_linkpriority3, display_name, raw_contact_linkpriority2, raw_contact_linkpriority1, sort_key_alt, has_email, in_visible_group, dirty_contact, starred, link_count, sort_key, display_name_alt, agg_presence.mode AS contact_presence, contacts_status_updates.status_res_package AS contact_status_res_package, contacts_status_updates.status_ts AS contact_status_ts FROM view_contacts_restricted JOIN (SELECT contact_id AS snippet_contact_id, ifnull('['||(SELECT MIN(data1) FROM data JOIN raw_contacts ON (data.raw_contact_id = raw_contacts._id) JOIN phone_lookup ON data._id=phone_lookup.data_id WHERE search_index.contact_id=contact_id AND normalized_number LIKE '%+<phonenumber>%' OR normalized_number LIKE '%+<phonenumber>%')||']',snippet(search_index,'[',']','...',1,-10)) AS snippet FROM search_index WHERE search_index MATCH content:<phonenumber>* OR name:2024121E20201E14122412* UNION SELECT contact_id AS snippet_contact_id, NULL AS snippet FROM phone_lookup JOIN raw_contacts ON ( raw_contacts._id=raw_contact_id) WHERE normalized_number LIKE '%+<phonenumber>%') ON (_id=snippet_contact_id) LEFT OUTER JOIN agg_presence ON (_id = agg_presence.presence_contact_id) LEFT OUTER JOIN status_updates contacts_status_updates ON (status_update_id=contacts_status_updates.status_update_data_id)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:184)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:372)
at android.content.ContentResolver.query(ContentResolver.java:315)
at android.support.v4.content.CursorLoader.loadInBackground(Unknown Source)
at android.support.v4.content.CursorLoader.loadInBackground(Unknown Source)
at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(Unknown Source)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(Unknown Source)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(Unknown Source)
at android.support.v4.content.ModernAsyncTask$2.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more

【问题讨论】:

实际上是用户搜索的联系人的电话号码 【参考方案1】:
SQLiteException: near ":<phonenumber>": syntax error ... while compiling:
... WHERE search_index MATCH content:<phonenumber>* OR name:2024121E20201E14122412* ...

MATCH 适用于字符串。代码忘记在它们周围加上引号,如下所示:

... MATCH 'content:<phonenumber>* OR name:2024121E20201E14122412*' ...

这似乎是该版本的 Android 联系人内容提供程序中的一个错误。

【讨论】:

那为什么这个异常只出现在运行JB的那两台设备上呢? mUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); sql请求就是这样产生的。 我的应用程序出现同样的错误。 @nixan:您找到解决方案或答案了吗?为什么会出现此错误?

以上是关于使用联系人 API 时,SG SIII 和注 2 的 JB 更新异常的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Android Studios 中更新联系人的电话号码

地图上图例和注记有啥不同 (尽量简洁明了)谢

LA5059Playing With Stones (SG函数)

SG函数

wrjhdiqd0Supp0rt(支持Ml配置和注

在 Laravel 8 中使用 API 路由时返回错误