如果在Intent.ACTION_INSERT之后调用contentResolver.query(ContactsContract.Contacts.CONTENT_URI ...)返回0个游标 [英] contentResolver.query(ContactsContract.Contacts.CONTENT_URI...) return 0 count Cursor if called after Intent.ACTION_INSERT
问题描述
在华为P8 上测试我的应用时,我的行为很奇怪.一切在模拟器(Android版本4、5、6、7)以及 ASUS (Android 6)和 Samsung Galaxy S2 (Android 4.2)上均可正常运行.
I'm getting a weird behavior when testing my app on Huawei P8. Everything works nice on emulators (android version 4, 5, 6, 7) and on ASUS (android 6) and Samsung Galaxy S2 (Android 4.2).
以下步骤适用于物理设备和仿真器.调用contentResolver.query()
后,我得到了设备所有联系人的光标.
The following steps work both on physical device and emulators. After calling contentResolver.query()
I get a Cursor with all the contacts of my device.
- 我打开我的应用
- 我打电话给
contentResolver.query(ContactsContract.Contacts.CONTENT_URI...);
除了在我的 Huawei P8 上,以下步骤适用于所有地方;我的 Huawei P8 ,只有它,我得到了0个游标
The following steps work everywhere except on my Huawei P8; with my Huawei P8, and only with it, I get a 0 count Cursor
- 我打开我的应用
- 在我的应用中,打开
Intent
在设备上添加新联系人 - 我添加了一个新联系人,或者我不添加联系人就关闭了活动
- 我打电话给
contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
- I open my app
- From my app, I open an
Intent
to add a new contact on the device - I add a new contact or I close the activity without adding contact
- I call
contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
这是我在设备上获取联系人的方式:
This is how I get the contacts on the device:
ContentResolver contentResolver = getBaseContext().getContentResolver();
Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
这是我从应用程序打开在设备上添加新联系人的活动
This is how I open, from my app, the activity to add a new contact on the device
Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
intent.putExtra("finishActivityOnSaveCompleted", true);
startActivityForResult(intent, 101);
似乎在调用new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI)
之后,联系表已锁定".
It's seems that after calling new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI)
the contact table is "locked".
我是否必须以某种方式关闭"意图才能查询ContactsContract.Contacts.CONTENT_URI
?
Do I have to "close" the Intent someway to be able to query ContactsContract.Contacts.CONTENT_URI
?
重要提示:例如,如果我呼叫Intent.ACTION_CALL
而不是Intent.ACTION_INSERT
,我不会遇到任何问题,并且可以成功查询ContactsContract.Contacts.CONTENT_URI
.因此,问题在于在华为P8上查询ContactsContract.Contacts.CONTENT_URI
之后,正在呼叫" Intent.ACTION_INSERT
.
IMPORTANT: if, for example, instead of Intent.ACTION_INSERT
I call Intent.ACTION_CALL
I don't get any problem and I'm able to query successfully ContactsContract.Contacts.CONTENT_URI
. So, the problem is "calling" Intent.ACTION_INSERT
and after query ContactsContract.Contacts.CONTENT_URI
on Huawei P8.
谢谢你.
推荐答案
(为完整性起见,我将其作为答案)
这可能是设备错误,请在其他设备上尝试相同的代码.
This might be a device bug, try the same code on some other device.
这篇关于如果在Intent.ACTION_INSERT之后调用contentResolver.query(ContactsContract.Contacts.CONTENT_URI ...)返回0个游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!