CB-11206 (android) Fixed custom IM protocol parsing close #128
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/7f662d6c Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/7f662d6c Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/7f662d6c Branch: refs/heads/2.2.x Commit: 7f662d6c67ac08a96adef633dd426cf998421296 Parents: 534d16c Author: Alexander Sorokin <alexander.soro...@akvelon.com> Authored: Fri Oct 28 20:50:37 2016 +0300 Committer: Alexander Sorokin <alexander.soro...@akvelon.com> Committed: Fri Oct 28 20:50:37 2016 +0300 ---------------------------------------------------------------------- src/android/ContactAccessorSdk5.java | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/7f662d6c/src/android/ContactAccessorSdk5.java ---------------------------------------------------------------------- diff --git a/src/android/ContactAccessorSdk5.java b/src/android/ContactAccessorSdk5.java index 1ef0e6c..8f7135e 100644 --- a/src/android/ContactAccessorSdk5.java +++ b/src/android/ContactAccessorSdk5.java @@ -904,7 +904,15 @@ public class ContactAccessorSdk5 extends ContactAccessor { im.put("id", cursor.getString(cursor.getColumnIndex(CommonDataKinds.Im._ID))); im.put("pref", false); // Android does not store pref attribute im.put("value", cursor.getString(cursor.getColumnIndex(CommonDataKinds.Im.DATA))); - im.put("type", getImType(Integer.parseInt(cursor.getString(cursor.getColumnIndex(CommonDataKinds.Im.PROTOCOL))))); + String protocol = cursor.getString(cursor.getColumnIndex(CommonDataKinds.Im.PROTOCOL)); + if (!isInteger(protocol) || Integer.parseInt(protocol) == CommonDataKinds.Im.PROTOCOL_CUSTOM) { + // the protocol is custom, get its name and put it into JSON + protocol = cursor.getString(cursor.getColumnIndex(CommonDataKinds.Im.CUSTOM_PROTOCOL)); + im.put("type", protocol); + } else { + // (the protocol is one of the standard ones) look up its type and then put it into JSON + im.put("type", getImType(Integer.parseInt(protocol))); + } } catch (JSONException e) { LOG.e(LOG_TAG, e.getMessage(), e); } @@ -2290,4 +2298,19 @@ public class ContactAccessorSdk5 extends ContactAccessor { return stringType; } + /** + * checks if a String can be converted to an Integer + * @param str + * @return boolean + */ + private static boolean isInteger(String str) { + try { + Integer.parseInt(str); + return true; + } + catch(Exception e) { + return false; + } + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org