contentResolver.query(ContactsContract.Contacts.CONTENT_URI…) return 0 count Cursor if called after Intent.ACTION_INSERT

南笙酒味 提交于 2019-12-11 10:50:37

问题


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).

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.

  1. I open my app
  2. I call contentResolver.query(ContactsContract.Contacts.CONTENT_URI...);

The following steps work everywhere except on my Huawei P8; with my Huawei P8, and only with it, I get a 0 count Cursor

  1. I open my app
  2. From my app, I open an Intent to add a new contact on the device
  3. I add a new contact or I close the activity without adding contact
  4. 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);

It's seems that after calling new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI) the contact table is "locked".

Do I have to "close" the Intent someway to be able to query ContactsContract.Contacts.CONTENT_URI?

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.

Thank you in adavance.


回答1:


(For completeness, I'll make this an answer)

This might be a device bug, try the same code on some other device.



来源:https://stackoverflow.com/questions/45275087/contentresolver-querycontactscontract-contacts-content-uri-return-0-count-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!