You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Vladimir Kotikov (JIRA)" <ji...@apache.org> on 2015/11/26 13:56:11 UTC

[jira] [Closed] (CB-8048) Contact.pickContact API should call getContactByRawId to fetch already existing contact

     [ https://issues.apache.org/jira/browse/CB-8048?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Vladimir Kotikov closed CB-8048.
--------------------------------
    Resolution: Invalid

> 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: 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
>            Assignee: Vladimir Kotikov
>            Priority: Minor
>              Labels: Android, triaged
>
> 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
> {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));
> }
> }
> {code}
> Modified Code : Changed the call " JSONObject contact = contactAccessor.getContactByRawId(id);"
> {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); 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));
> }
> }
> {code}
> 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: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org