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.
- I open my app
- 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
- 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);
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.