Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

In this page you can find the example usage for org.json JSONException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.projectgoth.mywebrtcdemo.WebSocketChannelClient.java

public void send(String message) {
    checkIfCalledOnValidThread();//from  ww w .  ja  v  a2 s . c  o m
    switch (state) {
    case NEW:
    case CONNECTED:
        // Store outgoing messages and send them after websocket client
        // is registered.
        Log.d(TAG, "WS ACC: " + message);
        wsSendQueue.add(message);
        return;
    case ERROR:
    case CLOSED:
        Log.e(TAG, "WebSocket send() in error or closed state : " + message);
        return;
    case REGISTERED:
        JSONObject json = new JSONObject();
        try {
            json.put("cmd", "send");
            json.put("msg", message);
            message = json.toString();
            Log.d(TAG, "C->WSS: " + message);
            ws.sendTextMessage(message);
        } catch (JSONException e) {
            reportError("WebSocket send JSON error: " + e.getMessage());
        }
        break;
    }
    return;
}

From source file:com.nebel_tv.content.services.MediasServiceTest.java

/**
 * Test of getMediaItem request of service IvaWrapperWeb (remote server).
 *
 * @param url Service URL//from   w  ww .j  av a 2 s .c  om
 */
public void testServiceRequest(String url) {
    try {
        String response = IOUtils.toString(new URL(url));
        assertTrue(response != null && !response.isEmpty());

        JSONArray jsonGetMedias = new JSONArray(response);
        assertFalse(jsonGetMedias.length() == 0);

        for (int i = 0; i < jsonGetMedias.length(); i++) {
            JSONObject jsonItem = jsonGetMedias.getJSONObject(i);
            testJsonMediaItem(jsonItem);
        }
    } catch (JSONException e) {
        fail("JSON parsing failed" + e.getMessage());
    } catch (IOException e) {
        fail("Web service request failed " + e.getMessage());
    }
}

From source file:org.uiautomation.ios.server.application.APPIOSApplication.java

private String getFirstIconFile(String bundleIcons) {
    if (!metadata.has(bundleIcons)) {
        return "";
    }//from w w w . j ava2 s  .  c om
    try {
        HashMap icons = (HashMap) metadata.get(bundleIcons);
        HashMap primaryIcon = (HashMap) icons.get("CFBundlePrimaryIcon");
        ArrayList iconFiles = (ArrayList) primaryIcon.get("CFBundleIconFiles");
        return iconFiles.get(0).toString();
    } catch (JSONException e) {
        throw new WebDriverException("property 'CFBundleIcons' can't be returned. " + e.getMessage(), e);
    }
}

From source file:org.uiautomation.ios.server.application.APPIOSApplication.java

public String getMetadata(String key) {
    if (!metadata.has(key)) {
        return "";
        // throw new WebDriverException("no property " + key +
        // " for this app.");
    }/*from w w  w . j a v a2s.  c om*/
    try {
        return metadata.getString(key);
    } catch (JSONException e) {
        throw new WebDriverException("property " + key + " can't be returned. " + e.getMessage(), e);
    }
}

From source file:com.waageweb.sunshine.app.FetchWeatherTask.java

/**
 * Take the String representing the complete forecast in JSON Format and
 * pull out the data we need to construct the Strings needed for the wireframes.
 *
 * Fortunately parsing is easy:  constructor takes the JSON string and converts it
 * into an Object hierarchy for us.//from   w w  w  .  j  av  a2  s  .com
 */
private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException {

    // Now we have a String representing the complete forecast in JSON Format.
    // Fortunately parsing is easy:  constructor takes the JSON string and converts it
    // into an Object hierarchy for us.

    // These are the names of the JSON objects that need to be extracted.

    // Location information
    final String OWM_CITY = "city";
    final String OWM_CITY_NAME = "name";
    final String OWM_COORD = "coord";

    // Location coordinate
    final String OWM_LATITUDE = "lat";
    final String OWM_LONGITUDE = "lon";

    // Weather information.  Each day's forecast info is an element of the "list" array.
    final String OWM_LIST = "list";

    final String OWM_PRESSURE = "pressure";
    final String OWM_HUMIDITY = "humidity";
    final String OWM_WINDSPEED = "speed";
    final String OWM_WIND_DIRECTION = "deg";

    // All temperatures are children of the "temp" object.
    final String OWM_TEMPERATURE = "temp";
    final String OWM_MAX = "max";
    final String OWM_MIN = "min";

    final String OWM_WEATHER = "weather";
    final String OWM_DESCRIPTION = "main";
    final String OWM_WEATHER_ID = "id";

    try {
        JSONObject forecastJson = new JSONObject(forecastJsonStr);
        JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST);

        JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY);
        String cityName = cityJson.getString(OWM_CITY_NAME);

        JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD);
        double cityLatitude = cityCoord.getDouble(OWM_LATITUDE);
        double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE);

        long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude);

        // Insert the new weather information into the database
        Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length());

        // OWM returns daily forecasts based upon the local time of the city that is being
        // asked for, which means that we need to know the GMT offset to translate this data
        // properly.

        // Since this data is also sent in-order and the first day is always the
        // current day, we're going to take advantage of that to get a nice
        // normalized UTC date for all of our weather.

        Time dayTime = new Time();
        dayTime.setToNow();

        // we start at the day returned by local time. Otherwise this is a mess.
        int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff);

        // now we work exclusively in UTC
        dayTime = new Time();

        for (int i = 0; i < weatherArray.length(); i++) {
            // These are the values that will be collected.
            long dateTime;
            double pressure;
            int humidity;
            double windSpeed;
            double windDirection;

            double high;
            double low;

            String description;
            int weatherId;

            // Get the JSON object representing the day
            JSONObject dayForecast = weatherArray.getJSONObject(i);

            // Cheating to convert this to UTC time, which is what we want anyhow
            dateTime = dayTime.setJulianDay(julianStartDay + i);

            pressure = dayForecast.getDouble(OWM_PRESSURE);
            humidity = dayForecast.getInt(OWM_HUMIDITY);
            windSpeed = dayForecast.getDouble(OWM_WINDSPEED);
            windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION);

            // Description is in a child array called "weather", which is 1 element long.
            // That element also contains a weather code.
            JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0);
            description = weatherObject.getString(OWM_DESCRIPTION);
            weatherId = weatherObject.getInt(OWM_WEATHER_ID);

            // Temperatures are in a child object called "temp".  Try not to name variables
            // "temp" when working with temperature.  It confuses everybody.
            JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE);
            high = temperatureObject.getDouble(OWM_MAX);
            low = temperatureObject.getDouble(OWM_MIN);

            ContentValues weatherValues = new ContentValues();

            weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId);
            weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime);
            weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity);
            weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure);
            weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed);
            weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection);
            weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high);
            weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low);
            weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description);
            weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId);

            cVVector.add(weatherValues);
        }

        int inserted = 0;
        // add to database
        if (cVVector.size() > 0) {
            // Student: call bulkInsert to add the weatherEntries to the database here

            ContentValues[] cvArray = new ContentValues[cVVector.size()];
            cVVector.toArray(cvArray);
            inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray);

        }

        Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted");

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }
}

From source file:org.akvo.flow.api.parser.json.QuestionResponseParser.java

public QuestionResponse parse(JSONObject jSurveyedLocale) {
    try {// ww w  . ja va 2  s .c o  m
        String val = jSurveyedLocale.getString(Attrs.ANSWER);
        String questionId = jSurveyedLocale.getString(Attrs.QUESTION_ID);

        return new QuestionResponse(val, ConstantUtil.VALUE_RESPONSE_TYPE, questionId);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
        return null;
    }
}

From source file:org.akvo.flow.api.parser.json.QuestionResponseParser.java

public List<QuestionResponse> parseList(JSONArray jResponses) {
    List<QuestionResponse> responses = new ArrayList<QuestionResponse>();
    try {/*from  w ww  .  j a v a  2 s  .  c o m*/
        for (int i = 0; i < jResponses.length(); i++) {
            JSONObject jQResponse = jResponses.getJSONObject(i);
            QuestionResponse response = parse(jQResponse);
            if (response != null) {
                responses.add(response);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }

    return responses;
}

From source file:org.apache.cordova.contacts.ContactAccessorSdk5.java

/**
 * Creates an array of contacts from the cursor you pass in
 *
 * @param limit        max number of contacts for the array
 * @param populate     whether or not you should populate a certain value
 * @param c            the cursor//  ww w .j  av  a  2s.  c o m
 * @return             a JSONArray of contacts
 */
private JSONArray populateContactArray(int limit, HashMap<String, Boolean> populate, Cursor c) {

    String contactId = "";
    String rawId = "";
    String oldContactId = "";
    boolean newContact = true;
    String mimetype = "";

    JSONArray contacts = new JSONArray();
    JSONObject contact = new JSONObject();
    JSONArray organizations = new JSONArray();
    JSONArray addresses = new JSONArray();
    JSONArray phones = new JSONArray();
    JSONArray emails = new JSONArray();
    JSONArray ims = new JSONArray();
    JSONArray websites = new JSONArray();
    JSONArray photos = new JSONArray();

    // Column indices
    int colContactId = c.getColumnIndex(ContactsContract.Data.CONTACT_ID);
    int colRawContactId = c.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID);
    int colMimetype = c.getColumnIndex(ContactsContract.Data.MIMETYPE);
    int colDisplayName = c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
    int colNote = c.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE);
    int colNickname = c.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME);
    int colBirthday = c.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE);
    int colEventType = c.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE);

    if (c.getCount() > 0) {
        while (c.moveToNext() && (contacts.length() <= (limit - 1))) {
            try {
                contactId = c.getString(colContactId);
                rawId = c.getString(colRawContactId);

                // If we are in the first row set the oldContactId
                if (c.getPosition() == 0) {
                    oldContactId = contactId;
                }

                // When the contact ID changes we need to push the Contact object
                // to the array of contacts and create new objects.
                if (!oldContactId.equals(contactId)) {
                    // Populate the Contact object with it's arrays
                    // and push the contact into the contacts array
                    contacts.put(populateContact(contact, organizations, addresses, phones, emails, ims,
                            websites, photos));

                    // Clean up the objects
                    contact = new JSONObject();
                    organizations = new JSONArray();
                    addresses = new JSONArray();
                    phones = new JSONArray();
                    emails = new JSONArray();
                    ims = new JSONArray();
                    websites = new JSONArray();
                    photos = new JSONArray();

                    // Set newContact to true as we are starting to populate a new contact
                    newContact = true;
                }

                // When we detect a new contact set the ID and display name.
                // These fields are available in every row in the result set returned.
                if (newContact) {
                    newContact = false;
                    contact.put("id", contactId);
                    contact.put("rawId", rawId);
                }

                // Grab the mimetype of the current row as it will be used in a lot of comparisons
                mimetype = c.getString(colMimetype);

                if (mimetype.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                        && isRequired("name", populate)) {
                    contact.put("displayName", c.getString(colDisplayName));
                }

                if (mimetype.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                        && isRequired("name", populate)) {
                    contact.put("name", nameQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                        && isRequired("phoneNumbers", populate)) {
                    phones.put(phoneQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
                        && isRequired("emails", populate)) {
                    emails.put(emailQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
                        && isRequired("addresses", populate)) {
                    addresses.put(addressQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
                        && isRequired("organizations", populate)) {
                    organizations.put(organizationQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
                        && isRequired("ims", populate)) {
                    ims.put(imQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE)
                        && isRequired("note", populate)) {
                    contact.put("note", c.getString(colNote));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE)
                        && isRequired("nickname", populate)) {
                    contact.put("nickname", c.getString(colNickname));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE)
                        && isRequired("urls", populate)) {
                    websites.put(websiteQuery(c));
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)) {
                    if (isRequired("birthday", populate)
                            && ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY == c.getInt(colEventType)) {
                        contact.put("birthday", c.getString(colBirthday));
                    }
                } else if (mimetype.equals(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                        && isRequired("photos", populate)) {
                    JSONObject photo = photoQuery(c, contactId);
                    if (photo != null) {
                        photos.put(photo);
                    }
                }
            } catch (JSONException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }

            // Set the old contact ID
            oldContactId = contactId;

        }

        // Push the last contact into the contacts array
        if (contacts.length() < limit) {
            contacts.put(
                    populateContact(contact, organizations, addresses, phones, emails, ims, websites, photos));
        }
    }
    c.close();
    return contacts;
}

From source file:org.apache.cordova.contacts.ContactAccessorSdk5.java

/**
 * Create a new contact using a JSONObject to hold all the data.
 * @param contact/*from www.j  av  a2s.  c o m*/
 * @param organizations array of organizations
 * @param addresses array of addresses
 * @param phones array of phones
 * @param emails array of emails
 * @param ims array of instant messenger addresses
 * @param websites array of websites
 * @param photos
 * @return
 */
private JSONObject populateContact(JSONObject contact, JSONArray organizations, JSONArray addresses,
        JSONArray phones, JSONArray emails, JSONArray ims, JSONArray websites, JSONArray photos) {
    try {
        // Only return the array if it has at least one entry
        if (organizations.length() > 0) {
            contact.put("organizations", organizations);
        }
        if (addresses.length() > 0) {
            contact.put("addresses", addresses);
        }
        if (phones.length() > 0) {
            contact.put("phoneNumbers", phones);
        }
        if (emails.length() > 0) {
            contact.put("emails", emails);
        }
        if (ims.length() > 0) {
            contact.put("ims", ims);
        }
        if (websites.length() > 0) {
            contact.put("urls", websites);
        }
        if (photos.length() > 0) {
            contact.put("photos", photos);
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    return contact;
}

From source file:org.apache.cordova.contacts.ContactAccessorSdk5.java

/**
 * Take the search criteria passed into the method and create a SQL WHERE clause.
 * @param fields the properties to search against
 * @param searchTerm the string to search for
 * @return an object containing the selection and selection args
 *//*from   ww  w.j a  v  a 2  s. c o  m*/
private WhereOptions buildWhereClause(JSONArray fields, String searchTerm) {

    ArrayList<String> where = new ArrayList<String>();
    ArrayList<String> whereArgs = new ArrayList<String>();

    WhereOptions options = new WhereOptions();

    /*
     * Special case where the user wants all fields returned
     */
    if (isWildCardSearch(fields)) {
        // Get all contacts with all properties
        if ("%".equals(searchTerm)) {
            options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
            options.setWhereArgs(new String[] { searchTerm });
            return options;
        } else {
            // Get all contacts that match the filter but return all properties
            where.add("(" + dbMap.get("displayName") + " LIKE ? )");
            whereArgs.add(searchTerm);
            where.add("(" + dbMap.get("name") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("nickname") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("phoneNumbers") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE
                    + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("emails") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
            where.add(
                    "(" + dbMap.get("addresses") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("ims") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("organizations") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE
                    + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("note") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
            where.add("(" + dbMap.get("urls") + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
            whereArgs.add(searchTerm);
            whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
        }
    }

    /*
     * Special case for when the user wants all the contacts but
     */
    if ("%".equals(searchTerm)) {
        options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
        options.setWhereArgs(new String[] { searchTerm });
        return options;
    }

    String key;
    try {
        //Log.d(LOG_TAG, "How many fields do we have = " + fields.length());
        for (int i = 0; i < fields.length(); i++) {
            key = fields.getString(i);

            if (key.equals("id")) {
                where.add("(" + dbMap.get(key) + " = ? )");
                whereArgs.add(searchTerm.substring(1, searchTerm.length() - 1));
            } else if (key.startsWith("displayName")) {
                where.add("(" + dbMap.get(key) + " LIKE ? )");
                whereArgs.add(searchTerm);
            } else if (key.startsWith("name")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("nickname")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("phoneNumbers")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("emails")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("addresses")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("ims")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("organizations")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
            }
            //        else if (key.startsWith("birthday")) {
            //          where.add("(" + dbMap.get(key) + " LIKE ? AND "
            //              + ContactsContract.Data.MIMETYPE + " = ? )");
            //        }
            else if (key.startsWith("note")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
            } else if (key.startsWith("urls")) {
                where.add("(" + dbMap.get(key) + " LIKE ? AND " + ContactsContract.Data.MIMETYPE + " = ? )");
                whereArgs.add(searchTerm);
                whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
            }
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }

    // Creating the where string
    StringBuffer selection = new StringBuffer();
    for (int i = 0; i < where.size(); i++) {
        selection.append(where.get(i));
        if (i != (where.size() - 1)) {
            selection.append(" OR ");
        }
    }
    options.setWhere(selection.toString());

    // Creating the where args array
    String[] selectionArgs = new String[whereArgs.size()];
    for (int i = 0; i < whereArgs.size(); i++) {
        selectionArgs[i] = whereArgs.get(i);
    }
    options.setWhereArgs(selectionArgs);

    return options;
}