List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:com.citrus.sdk.database.DBHandler.java
public void addPayOption(JSONArray paymentArray) { SQLiteDatabase db = this.getWritableDatabase(); for (int i = 0; i < paymentArray.length(); i++) { ContentValues loadValue = new ContentValues(); try {/* w w w .j a v a 2s . co m*/ JSONObject payOption = paymentArray.getJSONObject(i); loadValue.put(MMID, payOption.getString(MMID)); loadValue.put(SCHEME, payOption.getString(SCHEME)); loadValue.put(EXPDATE, payOption.getString(EXPDATE)); loadValue.put(NAME, payOption.getString(NAME)); loadValue.put(OWNER, payOption.getString(OWNER)); loadValue.put(BANK, payOption.getString(BANK)); loadValue.put(NUMBER, payOption.getString(NUMBER)); loadValue.put(TYPE, payOption.getString(TYPE).toUpperCase()); loadValue.put(IMPS_REGISTERED, payOption.getString(IMPS_REGISTERED)); loadValue.put(TOKEN_ID, payOption.getString(TOKEN_ID)); } catch (JSONException e) { throw new RuntimeException(e); } db.insert(PAYOPTION_TABLE, null, loadValue); } }
From source file:com.example.android.miniweather.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*w w w . j a v a2s . c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor; long locationID; cursor = contentResolver.query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { int locationIDIndex = cursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationID = cursor.getLong(locationIDIndex); } else { ContentValues newLocation = new ContentValues(); Uri insertedUri; newLocation.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); newLocation.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); newLocation.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); newLocation.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); insertedUri = contentResolver.insert(WeatherContract.LocationEntry.CONTENT_URI, newLocation); locationID = ContentUris.parseId(insertedUri); } cursor.close(); return locationID; }
From source file:com.mobileaffairs.seminar.videolib.VideoLibSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {//from w w w.ja va 2 s . c o m String videosJson = readVideosFromRemoteService(); try { JSONArray jsonArray = new JSONArray(videosJson); Log.i("SyncAdapter", "Number of entries " + jsonArray.length()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Cursor cs = provider.getLocalContentProvider().query( Uri.parse(VideoLibContentProvider.CONTENT_URI + "/" + jsonObject.getString("id")), null, null, null, null); long count = cs.getCount(); cs.close(); if (count == 0) { ContentValues values = new ContentValues(); values.put("_id", jsonObject.getString("id")); values.put("title", jsonObject.getString("title")); values.put("duration", jsonObject.getString("duration")); values.put("videoUrl", jsonObject.getString("url")); byte[] imageBytes = readImage(jsonObject.getString("thumbnail_small")); if (imageBytes != null && imageBytes.length > 0) { values.put("thumbnail", imageBytes); } provider.getLocalContentProvider().insert(VideoLibContentProvider.CONTENT_URI, values); } syncResult.fullSyncRequested = true; } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.example.richa.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city * @param lon the longitude of the city * @return the row ID of the added location. *///from w w w.j ava2 s.c o m long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db long locationId; Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); // If it exists, return the current ID if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Otherwise, insert it using the content resolver and the base URI //Now, that the content provider is set up, inserting rows of data is very simple //First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); //Then add the data, along with the corresponding name of the data type, //so the content provider knows what kind of value is being inserted. locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); //560034 locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:it.ms.theing.loquitur.functions.Storage.java
/** * Set a key. If the value already exists is overwritten * @param genre/* ww w . ja va 2 s . c o m*/ * The genre of the key * @param key * The key * @param value * The key value */ @JavascriptInterface public void setKey(String genre, String key, String value) { ContentValues val = new ContentValues(); val.put("genre", genre.toUpperCase()); val.put("key", key); val.put("value", value); dataBase.insert("alias", null, val); }
From source file:com.waageweb.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from w w w .j a v a 2 s . c om*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { // If it exists, return the current ID return locationCursor.getLong(locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID)); } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, "" + lat); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, "" + lon); Uri uriInserted = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); // Otherwise, insert it using the content resolver and the base URI return ContentUris.parseId(uriInserted); } }
From source file:com.bt.download.android.gui.UniversalScanner.java
private void scanDocument(String filePath) { File file = new File(filePath); if (documentExists(filePath, file.length())) { return;// w w w . j ava 2 s . c o m } String displayName = FilenameUtils.getBaseName(file.getName()); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(DocumentsColumns.DATA, filePath); values.put(DocumentsColumns.SIZE, file.length()); values.put(DocumentsColumns.DISPLAY_NAME, displayName); values.put(DocumentsColumns.TITLE, displayName); values.put(DocumentsColumns.DATE_ADDED, System.currentTimeMillis()); values.put(DocumentsColumns.DATE_MODIFIED, file.lastModified()); values.put(DocumentsColumns.MIME_TYPE, UIUtils.getMimeType(filePath)); Uri uri = cr.insert(Documents.Media.CONTENT_URI, values); FileDescriptor fd = new FileDescriptor(); fd.fileType = Constants.FILE_TYPE_DOCUMENTS; fd.id = Integer.valueOf(uri.getLastPathSegment()); shareFinishedDownload(fd); }
From source file:fr.free.nrw.commons.contributions.ContributionDao.java
ContentValues toContentValues(Contribution contribution) { ContentValues cv = new ContentValues(); cv.put(Table.COLUMN_FILENAME, contribution.getFilename()); if (contribution.getLocalUri() != null) { cv.put(Table.COLUMN_LOCAL_URI, contribution.getLocalUri().toString()); }/* w w w. j a v a 2 s . c o m*/ if (contribution.getImageUrl() != null) { cv.put(Table.COLUMN_IMAGE_URL, contribution.getImageUrl()); } if (contribution.getDateUploaded() != null) { cv.put(Table.COLUMN_UPLOADED, contribution.getDateUploaded().getTime()); } cv.put(Table.COLUMN_LENGTH, contribution.getDataLength()); //This was always meant to store the date created..If somehow date created is not fetched while actually saving the contribution, lets save today's date cv.put(Table.COLUMN_TIMESTAMP, contribution.getDateCreated() == null ? System.currentTimeMillis() : contribution.getDateCreated().getTime()); cv.put(Table.COLUMN_STATE, contribution.getState()); cv.put(Table.COLUMN_TRANSFERRED, contribution.getTransferred()); cv.put(Table.COLUMN_SOURCE, contribution.getSource()); cv.put(Table.COLUMN_DESCRIPTION, contribution.getDescription()); cv.put(Table.COLUMN_CREATOR, contribution.getCreator()); cv.put(Table.COLUMN_MULTIPLE, contribution.getMultiple() ? 1 : 0); cv.put(Table.COLUMN_WIDTH, contribution.getWidth()); cv.put(Table.COLUMN_HEIGHT, contribution.getHeight()); cv.put(Table.COLUMN_LICENSE, contribution.getLicense()); cv.put(Table.COLUMN_WIKI_DATA_ENTITY_ID, contribution.getWikiDataEntityId()); return cv; }
From source file:com.aleix.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from www. j a v a 2 s .c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI long locationId; // First, check if the location with this city name exists in the db Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); // Wait, that worked? Yes! return locationId; }
From source file:com.tigerbase.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from www. j a v a 2 s. co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI Log.v(LOG_TAG, "addLocation"); Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); long locationId = 0; if (locationCursor.moveToFirst()) { Log.v(LOG_TAG, "addLocation: Found location"); int idColumnIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(idColumnIndex); } locationCursor.close(); if (locationId > 0) { Log.v(LOG_TAG, "addLocation: Return Location " + locationId); return locationId; } ContentValues newLocationValues = new ContentValues(); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri newLocationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, newLocationValues); locationId = ContentUris.parseId(newLocationUri); Log.v(LOG_TAG, "addLocation: Created location " + locationId); return locationId; }