Pavankumar Joshi created CB-8048:
------------------------------------
Summary: Contact.pickContact API should call getContactByRawId to
fetch already existing contact
Key: CB-8048
URL: https://issues.apache.org/jira/browse/CB-8048
Project: Apache Cordova
Issue Type: Bug
Components: Android, mobile-spec, Plugin Contacts
Affects Versions: 3.6.3
Environment: Mobilespec 3.6.3 , Nexus 7 device, Android 4.4.3 version
on device
Reporter: Pavankumar Joshi
Priority: Minor
This Issue is related to https://issues.apache.org/jira/browse/CB-5308
I am constantly getting contact.save()(already existing contact) method test
failure.
If I apply the patch as mentioned in JIRA
https://issues.apache.org/jira/browse/CB-5308 pickContacts API fails.
But without the patch conact.save()(already existing contact) method always
fails.
I observed that the query to retrieve the contact which already exists
RAWCONTACTS_ID is used This is implemented in onActivityResult() in
ContactManager.java
Hence i made the change even to pickContact API.
Earlier Code
public void onActivityResult(int requestCode, int resultCode, final Intent
intent) {
if (requestCode == CONTACT_PICKER_RESULT) {
if (resultCode == Activity.RESULT_OK) {
String contactId = intent.getData().getLastPathSegment();
// to populate contact data we require Raw Contact ID
// so we do look up for contact raw id first
Cursor c =
this.cordova.getActivity().getContentResolver().query(RawContacts.CONTENT_URI,
new String[]
{RawContacts._ID}, RawContacts.CONTACT_ID + " = " + contactId, null, null);
if (!c.moveToFirst()) { this.callbackContext.error("Error occured while
retrieving contact raw id"); return; }
String id = c.getString(c.getColumnIndex(RawContacts._ID));
c.close();
try { JSONObject contact = contactAccessor.getContactById(id);
this.callbackContext.success(contact); return; } catch (JSONException e) {
Log.e(LOG_TAG, "JSON fail.", e); }
} else if (resultCode == Activity.RESULT_CANCELED){
this.callbackContext.sendPluginResult(new
PluginResult(PluginResult.Status.NO_RESULT, UNKNOWN_ERROR)); return; }
this.callbackContext.sendPluginResult(new
PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
}
}
Modified Code : Changed the call " JSONObject contact =
contactAccessor.getContactByRawId(id);"
public void onActivityResult(int requestCode, int resultCode, final Intent
intent) {
if (requestCode == CONTACT_PICKER_RESULT) {
if (resultCode == Activity.RESULT_OK) {
String contactId = intent.getData().getLastPathSegment();
// to populate contact data we require Raw Contact ID
// so we do look up for contact raw id first
Cursor c =
this.cordova.getActivity().getContentResolver().query(RawContacts.CONTENT_URI,
new String[] {RawContacts._ID}
, RawContacts.CONTACT_ID + " = " + contactId, null, null);
if (!c.moveToFirst())
{ this.callbackContext.error("Error occured while retrieving contact raw id");
return; }
String id = c.getString(c.getColumnIndex(RawContacts._ID));
c.close();
try
{ //JSONObject contact = contactAccessor.getContactById(id); JSONObject contact
= contactAccessor.getContactByRawId(id); this.callbackContext.success(contact);
return; }
catch (JSONException e)
{ Log.e(LOG_TAG, "JSON fail.", e); }
} else if (resultCode == Activity.RESULT_CANCELED)
{ this.callbackContext.sendPluginResult(new
PluginResult(PluginResult.Status.NO_RESULT, UNKNOWN_ERROR)); return; }
this.callbackContext.sendPluginResult(new
PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
}
}
Please let me know if this is correct or are we missing something
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]