List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:com.android.transmart.services.PlaceCheckinService.java
/** * Adds a checkin to the {@link QueuedCheckinsContentProvider} to be retried. * @param timeStamp Checkin timestamp//from www . java 2s . c o m * @param reference Checkin venue reference * @param id Checkin venue unique identifier * @return Successfully added to the queue */ protected boolean addToQueue(long timeStamp, String reference, String id) { // Construct the new / updated row. ContentValues values = new ContentValues(); values.put(QueuedCheckinsContentProvider.KEY_REFERENCE, reference); values.put(QueuedCheckinsContentProvider.KEY_ID, id); values.put(QueuedCheckinsContentProvider.KEY_TIME_STAMP, timeStamp); String where = QueuedCheckinsContentProvider.KEY_REFERENCE + " = '" + reference + "'"; // Update the existing checkin for this venue or add the venue to the queue. try { if (contentResolver.update(QueuedCheckinsContentProvider.CONTENT_URI, values, where, null) == 0) { if (contentResolver.insert(QueuedCheckinsContentProvider.CONTENT_URI, values) != null) return true; return true; } } catch (Exception ex) { Log.e(TAG, "Queuing checkin for " + reference + " failed."); } return false; }
From source file:com.csipsimple.backup.SipProfileJson.java
private static boolean restoreSipProfile(JSONObject jsonObj, ContentResolver cr) { // Restore accounts Columns cols;/*from w w w. jav a 2 s. c o m*/ ContentValues cv; cols = getSipProfileColumns(false); cv = cols.jsonToContentValues(jsonObj); long profileId = cv.getAsLong(SipProfile.FIELD_ID); if (profileId >= 0) { Uri insertedUri = cr.insert(SipProfile.ACCOUNT_URI, cv); profileId = ContentUris.parseId(insertedUri); } // TODO : else restore call handler in private db // Restore filters cols = new Columns(Filter.FULL_PROJ, Filter.FULL_PROJ_TYPES); try { JSONArray filtersObj = jsonObj.getJSONArray(FILTER_KEY); Log.d(THIS_FILE, "We have filters for " + profileId + " > " + filtersObj.length()); for (int i = 0; i < filtersObj.length(); i++) { JSONObject filterObj = filtersObj.getJSONObject(i); // Log.d(THIS_FILE, "restoring "+filterObj.toString(4)); cv = cols.jsonToContentValues(filterObj); cv.put(Filter.FIELD_ACCOUNT, profileId); cr.insert(SipManager.FILTER_URI, cv); } } catch (JSONException e) { Log.e(THIS_FILE, "Error while restoring filters", e); } return false; }
From source file:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*w w w. j av a2 s . c om*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "border_wait" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(BORDER_WAIT_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("waittimes"); JSONArray items = result.getJSONArray("items"); List<ContentValues> times = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); ContentValues timesValues = new ContentValues(); timesValues.put(BorderWait.BORDER_WAIT_ID, item.getInt("id")); timesValues.put(BorderWait.BORDER_WAIT_TITLE, item.getString("name")); timesValues.put(BorderWait.BORDER_WAIT_UPDATED, item.getString("updated")); timesValues.put(BorderWait.BORDER_WAIT_LANE, item.getString("lane")); timesValues.put(BorderWait.BORDER_WAIT_ROUTE, item.getInt("route")); timesValues.put(BorderWait.BORDER_WAIT_DIRECTION, item.getString("direction")); timesValues.put(BorderWait.BORDER_WAIT_TIME, item.getInt("wait")); if (starred.contains(item.getInt("id"))) { timesValues.put(BorderWait.BORDER_WAIT_IS_STARRED, 1); } times.add(timesValues); } // Purge existing border wait times covered by incoming data resolver.delete(BorderWait.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(BorderWait.CONTENT_URI, times.toArray(new ContentValues[times.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "border_wait" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.BORDER_WAIT_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.citrus.sdk.database.DBHandler.java
public int setDefaultOption(String optionName) { String whereValues[] = new String[] { optionName }; SQLiteDatabase db = this.getWritableDatabase(); ContentValues newValues = new ContentValues(); if (!TextUtils.isEmpty(optionName)) { try {//w w w . ja v a 2 s.c om newValues.put(DEFAULT_OPTION, 1); return db.update(PAYOPTION_TABLE, newValues, NAME + "=?", whereValues); } catch (Exception e) { db.close(); return 0; } } else { try { newValues.put(DEFAULT_OPTION, 0); return db.update(PAYOPTION_TABLE, newValues, null, null); } catch (Exception e) { db.close(); return 0; } } }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTask.java
public ContentValues toGTasksContentValues(String accountName) { ContentValues values = new ContentValues(); values.put(NotePad.GTasks.COLUMN_NAME_DB_ID, dbid); // if (title.contains("debug")) // Log.d(TAG, title + " saving id: " + id); // values.put(NotePad.GTasks.COLUMN_NAME_ETAG, etag); // values.put(NotePad.GTasks.COLUMN_NAME_GOOGLE_ACCOUNT, accountName); // values.put(NotePad.GTasks.COLUMN_NAME_GTASKS_ID, id); values.put(NotePad.GTasks.COLUMN_NAME_UPDATED, updated); return values; }
From source file:com.pti.mates.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w w w . j a va 2 s . c o m*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); //sendNotification("Estem fent HandleIntent"); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { //sendNotification("Message type correcte"); // This loop represents the service doing some work. String type = intent.getStringExtra("type"); if (type.equals("message")) { String msg = intent.getStringExtra("data"); String senderid = intent.getStringExtra("sender"); String receiverid = intent.getStringExtra("receiver"); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal()); values.put(DataProvider.COL_MESSAGE, msg); values.put(DataProvider.COL_SENDERFBID, senderid); values.put(DataProvider.COL_RECEIVERFBID, receiverid); getApplicationContext().getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values); if (Common.isNotify()) { /*Cursor c = getApplicationContext().getContentResolver().query(DataProvider.CONTENT_URI_PROFILE, null, DataProvider.COL_FBID + "=" + senderid, null, null); int index = c.getColumnIndex(DataProvider.COL_NAME); String sendername; if (index != -1) { sendername = c.getString(index); } else { sendername = "name not available"; } sendNotificationChat("New message from " + sendername,senderid);*/ sendNotificationChat("New message", senderid); } } else if (type.equals("mate")) { //extreure info de la persona necessaria per crear el xat (insertar a la base de dades un nou perfil) //si fa falta cridar la activity per mostrar la info. (perfilActivity??) String userdatajson = intent.getStringExtra("data"); String fbid = getInfoFromJson(userdatajson, "id"); String name = getInfoFromJson(userdatajson, "name"); Log.d("Mate intent service", "fbid = " + fbid + " name = " + name); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_NAME, name); values.put(DataProvider.COL_FBID, fbid); getApplication().getContentResolver().insert(DataProvider.CONTENT_URI_PROFILE, values); sendNotificationMate("New Mate with " + name); } } /*else { String msg = intent.getExtras().toString(); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); String senderid = intent.getStringExtra("sender"); String receiverid = intent.getStringExtra("receiver"); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal()); values.put(DataProvider.COL_MESSAGE, msg); values.put(DataProvider.COL_SENDERFBID, senderid); values.put(DataProvider.COL_RECEIVERFBID, receiverid); getApplicationContext().getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values); if (Common.isNotify()) { sendNotification("New message"); } }*/ } else { //sendNotification("Extras empty"); } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;//from ww w.ja v a2s . c o m long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "travel_times" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(TRAVEL_TIMES_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("traveltimes"); JSONArray items = result.getJSONArray("items"); List<ContentValues> times = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); ContentValues timesValues = new ContentValues(); timesValues.put(TravelTimes.TRAVEL_TIMES_TITLE, item.getString("title")); timesValues.put(TravelTimes.TRAVEL_TIMES_CURRENT, item.getInt("current")); timesValues.put(TravelTimes.TRAVEL_TIMES_AVERAGE, item.getInt("average")); timesValues.put(TravelTimes.TRAVEL_TIMES_DISTANCE, item.getString("distance") + " miles"); timesValues.put(TravelTimes.TRAVEL_TIMES_ID, Integer.parseInt(item.getString("routeid"))); timesValues.put(TravelTimes.TRAVEL_TIMES_UPDATED, item.getString("updated")); if (starred.contains(Integer.parseInt(item.getString("routeid")))) { timesValues.put(TravelTimes.TRAVEL_TIMES_IS_STARRED, 1); } times.add(timesValues); } // Purge existing travel times covered by incoming data resolver.delete(TravelTimes.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(TravelTimes.CONTENT_URI, times.toArray(new ContentValues[times.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "travel_times" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.TRAVEL_TIMES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:heartware.com.heartware_master.DBAdapter.java
public void createProfile(HashMap<String, String> queryValues) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USERNAME, queryValues.get(USERNAME)); values.put(PASSWORD, queryValues.get(PASSWORD)); values.put(DIFFICULTY, queryValues.get(DIFFICULTY)); values.put(DISABILITY, queryValues.get(DISABILITY)); database.insert(PROFILES_TABLE, null, values); database.close();/*ww w. j a v a 2 s .c o m*/ }
From source file:com.example.android.myargmenuplanner.data.FetchJsonDataTask.java
private void getDataIngrFromJson(String JsonStr) throws JSONException { final String JSON_LIST = "ingredients"; final String JSON_NAME = "name"; final String JSON_QTY = "qty"; final String JSON_UNIT = "unit"; final String JSON_ID_FOOD = "id_food"; try {//w w w .j a v a2 s. co m JSONObject dataJson = new JSONObject(JsonStr); JSONArray ingrArray = dataJson.getJSONArray(JSON_LIST); Vector<ContentValues> cVVector = new Vector<ContentValues>(ingrArray.length()); for (int i = 0; i < ingrArray.length(); i++) { JSONObject ingr = ingrArray.getJSONObject(i); String id_food = ingr.getString(JSON_ID_FOOD); String name = ingr.getString(JSON_NAME); String qty = ingr.getString(JSON_QTY); String unit = ingr.getString(JSON_UNIT); ContentValues values = new ContentValues(); values.put(IngrEntry.COLUMN_ID_FOOD, id_food); values.put(IngrEntry.COLUMN_NAME, name); values.put(IngrEntry.COLUMN_QTY, qty); values.put(IngrEntry.COLUMN_UNIT, unit); cVVector.add(values); } int inserted = 0; // delete database int rowdeleted = mContext.getContentResolver().delete(IngrEntry.CONTENT_URI, null, null); // // add to database Log.i(LOG_TAG, "Creando registros en base de datos. Tabla Ingredientes "); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(IngrEntry.CONTENT_URI, cvArray); Log.i(LOG_TAG, "Registros nuevos creados en Tabla Ingredientes: " + inserted); } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:heartware.com.heartware_master.DBAdapter.java
public int updateProfile(HashMap<String, String> queryValues) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USERNAME, queryValues.get(USERNAME)); values.put(PASSWORD, queryValues.get(PROFILE_ID)); values.put(DIFFICULTY, queryValues.get(DIFFICULTY)); values.put(DISABILITY, queryValues.get(DISABILITY)); // update(TableName, ContentValueForTable, WhereClause, ArgumentForWhereClause) return database.update(PROFILES_TABLE, values, PROFILE_ID + " = ?", new String[] { queryValues.get(PROFILE_ID) }); }