List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java
/** * EventBus listener for Event Bundle//from ww w. j a va 2 s. c o m * @param {Bundle} event */ @Subscribe public void onEventMainThread(Bundle event) { if (event.containsKey("request")) { return; } String name = event.getString("name"); if (BackgroundGeolocationService.ACTION_START.equalsIgnoreCase(name)) { onStarted(event); } else if (BackgroundGeolocationService.ACTION_ON_MOTION_CHANGE.equalsIgnoreCase(name)) { boolean nowMoving = event.getBoolean("isMoving"); try { JSONObject locationData = new JSONObject(event.getString("location")); onMotionChange(nowMoving, locationData); } catch (JSONException e) { Log.e(TAG, "Error decoding JSON"); e.printStackTrace(); } } else if (BackgroundGeolocationService.ACTION_GET_LOCATIONS.equalsIgnoreCase(name)) { try { JSONObject params = new JSONObject(); params.put("locations", new JSONArray(event.getString("data"))); params.put("taskId", "android-bg-task-id"); PluginResult result = new PluginResult(PluginResult.Status.OK, params); getLocationsCallback.sendPluginResult(result); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); PluginResult result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); getLocationsCallback.sendPluginResult(result); } } else if (BackgroundGeolocationService.ACTION_SYNC.equalsIgnoreCase(name)) { Boolean success = event.getBoolean("success"); if (success) { try { JSONObject params = new JSONObject(); params.put("locations", new JSONArray(event.getString("data"))); params.put("taskId", "android-bg-task-id"); PluginResult result = new PluginResult(PluginResult.Status.OK, params); syncCallback.sendPluginResult(result); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { PluginResult result = new PluginResult(PluginResult.Status.IO_EXCEPTION, event.getString("message")); syncCallback.sendPluginResult(result); } } else if (BackgroundGeolocationService.ACTION_RESET_ODOMETER.equalsIgnoreCase(name)) { this.onResetOdometer(event); } else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(name)) { this.onChangePace(event); } else if (BackgroundGeolocationService.ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) { try { JSONArray json = new JSONArray(event.getString("data")); PluginResult result = new PluginResult(PluginResult.Status.OK, json); getGeofencesCallback.sendPluginResult(result); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); PluginResult result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); getGeofencesCallback.sendPluginResult(result); } } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GOOGLE_PLAY_SERVICES_CONNECT_ERROR)) { GoogleApiAvailability.getInstance() .getErrorDialog(this.cordova.getActivity(), event.getInt("errorCode"), 1001).show(); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_LOCATION_ERROR)) { this.onLocationError(event); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_ADD_GEOFENCE)) { this.onAddGeofence(event); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_ADD_GEOFENCES)) { this.onAddGeofence(event); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_HTTP_RESPONSE)) { this.onHttpResponse(event); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION)) { this.onLocationError(event); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_INSERT_LOCATION)) { this.onInsertLocation(event); } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GET_COUNT)) { this.onGetCount(event); } }
From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java
public void onHttpResponse(Bundle event) { PluginResult result;//from w w w. ja va2 s .c om try { JSONObject params = new JSONObject(); params.put("status", event.getInt("status")); params.put("responseText", event.getString("responseText")); result = new PluginResult(PluginResult.Status.OK, params); } catch (JSONException e) { e.printStackTrace(); result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); } result.setKeepCallback(true); for (CallbackContext callback : httpResponseCallbacks) { callback.sendPluginResult(result); } }
From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java
private void onMotionChange(boolean nowMoving, JSONObject location) { isMoving = nowMoving;//from ww w . j a va2 s .com PluginResult result; try { JSONObject params = new JSONObject(); params.put("location", location); params.put("isMoving", isMoving); params.put("taskId", "android-bg-task-id"); result = new PluginResult(PluginResult.Status.OK, params); } catch (JSONException e) { e.printStackTrace(); result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); } result.setKeepCallback(true); for (CallbackContext callback : motionChangeCallbacks) { callback.sendPluginResult(result); } }
From source file:org.eclipse.orion.server.npm.NpmServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*from www .j a v a 2 s .co m*/ JSONObject o = OrionServlet.readJSONRequest(req); String type = o.getString("type"); String cwd = o.getString("cwd"); cwd = new URI(cwd).getPath(); String args = null; if (type.equalsIgnoreCase("install")) { args = o.getString("package"); if (args.equalsIgnoreCase("null")) { args = null; } } String result = this.excuteCmd(type, cwd, args); resp.setStatus(HttpServletResponse.SC_OK); JSONObject jsonResult = new JSONObject(); //The property "cmdOutput" is used as a single string to respond back to client. jsonResult.put("cmdOutput", result); OrionServlet.writeJSONResponse(req, resp, jsonResult); } catch (JSONException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (IOException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (URISyntaxException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:com.dedipower.portal.android.ColoLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.cololanding_iclone); //Temp/*w w w .j a va 2 s . co m*/ list = (ListView) findViewById(R.id.ColoCabList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); ColoRacksAdaptor adapter = new ColoRacksAdaptor(ColoLanding.this, listOfColoRacks); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occurred."; //UpdateErrorMessage("An unrecoverable JSON Exception occurred."); } if (Success.equals("false")) { try { //UpdateErrorMessage(Colo.getString("msg")); ErrorMessage = Colo.getString("msg"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; //UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs", Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); ErrorMessage = ""; //UpdateErrorMessage(""); } catch (JSONException e) { ErrorMessage = "There are no Co-Location Cabinets in your account."; //UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } int ColoCount = ColoCabs.length(); if (ColoCount == 0) { //UpdateErrorMessage("There are no colocation cabinets for your account."); ErrorMessage = "There are no colocation cabinets for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"))); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); //temp /*try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show(); } if(Success == "false") { try { UpdateErrorMessage(Colo.getString("msg")); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs",Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } //OK lets actually do something useful ListView list = (ListView)findViewById(R.id.ColoCabList); List<ColoRacks> listOfColoRacks = new ArrayList<ColoRacks>(); int ColoCount = ColoCabs.length(); if(ColoCount == 0) { UpdateErrorMessage("There are no colocation cabinets for your account."); return; } for(int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"))); } catch (JSONException e) { Log.e("APIFuncs",e.getMessage()); } } ColoRacksAdaptor adapter = new ColoRacksAdaptor(this, listOfColoRacks); list.setAdapter(adapter); }*/ }
From source file:com.phonegap.ContactAccessorSdk5.java
/** * This method takes the fields required and search options in order to produce an * array of contacts that matches the criteria provided. * @param fields an array of items to be used as search criteria * @param options that can be applied to contact searching * @return an array of contacts /* w ww. j a va 2 s . c o m*/ */ @Override public JSONArray search(JSONArray fields, JSONObject options) { long totalEnd; long totalStart = System.currentTimeMillis(); // Get the find options String searchTerm = ""; int limit = Integer.MAX_VALUE; boolean multiple = true; if (options != null) { searchTerm = options.optString("filter"); if (searchTerm.length() == 0) { searchTerm = "%"; } else { searchTerm = "%" + searchTerm + "%"; } try { multiple = options.getBoolean("multiple"); if (!multiple) { limit = 1; } } catch (JSONException e) { // Multiple was not specified so we assume the default is true. } } else { searchTerm = "%"; } //Log.d(LOG_TAG, "Search Term = " + searchTerm); //Log.d(LOG_TAG, "Field Length = " + fields.length()); //Log.d(LOG_TAG, "Fields = " + fields.toString()); // Loop through the fields the user provided to see what data should be returned. HashMap<String, Boolean> populate = buildPopulationSet(fields); // Build the ugly where clause and where arguments for one big query. WhereOptions whereOptions = buildWhereClause(fields, searchTerm); // Get all the id's where the search term matches the fields passed in. Cursor idCursor = mApp.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.CONTACT_ID }, whereOptions.getWhere(), whereOptions.getWhereArgs(), ContactsContract.Data.CONTACT_ID + " ASC"); // Create a set of unique ids //Log.d(LOG_TAG, "ID cursor query returns = " + idCursor.getCount()); Set<String> contactIds = new HashSet<String>(); while (idCursor.moveToNext()) { contactIds.add(idCursor.getString(idCursor.getColumnIndex(ContactsContract.Data.CONTACT_ID))); } idCursor.close(); // Build a query that only looks at ids WhereOptions idOptions = buildIdClause(contactIds, searchTerm); // Do the id query Cursor c = mApp.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, idOptions.getWhere(), idOptions.getWhereArgs(), ContactsContract.Data.CONTACT_ID + " ASC"); //Log.d(LOG_TAG, "Cursor length = " + c.getCount()); 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(); if (c.getCount() > 0) { while (c.moveToNext() && (contacts.length() <= (limit - 1))) { try { contactId = c.getString(c.getColumnIndex(ContactsContract.Data.CONTACT_ID)); rawId = c.getString(c.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID)); // 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); contact.put("displayName", c.getString( c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME))); } // Grab the mimetype of the current row as it will be used in a lot of comparisons mimetype = c.getString(c.getColumnIndex(ContactsContract.Data.MIMETYPE)); 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(c.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE))); } else if (mimetype.equals(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE) && isRequired("nickname", populate)) { contact.put("nickname", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME))); } 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 (ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY == c .getInt(c.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE)) && isRequired("birthday", populate)) { contact.put("birthday", c.getString( c.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE))); } } else if (mimetype.equals(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE) && isRequired("photos", populate)) { photos.put(photoQuery(c, contactId)); } } 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(); totalEnd = System.currentTimeMillis(); Log.d(LOG_TAG, "Total time = " + (totalEnd - totalStart)); return contacts; }
From source file:com.phonegap.ContactAccessorSdk5.java
/** * Create a new contact using a JSONObject to hold all the data. * @param contact //from www .ja v a 2 s .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 { contact.put("organizations", organizations); contact.put("addresses", addresses); contact.put("phoneNumbers", phones); contact.put("emails", emails); contact.put("ims", ims); contact.put("websites", websites); contact.put("photos", photos); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return contact; }
From source file:com.phonegap.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 av a2s . 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 for when the user wants all the contacts */ 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.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; }
From source file:com.phonegap.ContactAccessorSdk5.java
/** * Create a ContactOrganization JSONObject * @param cursor the current database row * @return a JSONObject representing a ContactOrganization */// ww w .j av a 2s . c om private JSONObject organizationQuery(Cursor cursor) { JSONObject organization = new JSONObject(); try { organization.put("id", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization._ID))); organization.put("department", cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DEPARTMENT))); organization.put("name", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.COMPANY))); organization.put("title", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE))); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return organization; }
From source file:com.phonegap.ContactAccessorSdk5.java
/** * Create a ContactAddress JSONObject/* w ww. ja va2 s . c o m*/ * @param cursor the current database row * @return a JSONObject representing a ContactAddress */ private JSONObject addressQuery(Cursor cursor) { JSONObject address = new JSONObject(); try { address.put("id", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal._ID))); address.put("formatted", cursor.getString( cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS))); address.put("streetAddress", cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET))); address.put("locality", cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY))); address.put("region", cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION))); address.put("postalCode", cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE))); address.put("country", cursor .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY))); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return address; }