List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:com.cloudmine.api.db.RequestDBObject.java
public ContentValues toRequestContentValues() { ContentValues requestContentValues = new ContentValues(); requestContentValues.put(KEY_REQUEST_JSON_BODY, jsonBody); requestContentValues.put(KEY_REQUEST_SYNCHRONIZED, syncStatus.ordinal()); requestContentValues.put(KEY_REQUEST_TARGET_URL, requestUrl); requestContentValues.put(KEY_REQUEST_VERB, requestType.name()); requestContentValues.put(KEY_REQUEST_OBJECT_ID, objectId); requestContentValues.put(KEY_REQUEST_FILE_ID, fileId); return requestContentValues; }
From source file:com.moez.QKSMS.mmssms.Transaction.java
private static Uri createPartText(Context context, String id, String text) throws Exception { ContentValues mmsPartValue = new ContentValues(); mmsPartValue.put("mid", id); mmsPartValue.put("ct", "text/plain"); mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">"); mmsPartValue.put("text", text); Uri partUri = Uri.parse("content://mms/" + id + "/part"); Uri res = context.getContentResolver().insert(partUri, mmsPartValue); return res;// w w w. ja v a 2 s. com }
From source file:net.olejon.mdapp.InteractionsCardsActivity.java
private void search(final String string, boolean cache) { try {//w w w .ja v a2 s .c om RequestQueue requestQueue = Volley.newRequestQueue(mContext); String apiUri = getString(R.string.project_website_uri) + "api/1/interactions/?search=" + URLEncoder.encode(string.toLowerCase(), "utf-8"); if (!cache) requestQueue.getCache().remove(apiUri); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(apiUri, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); if (response.length() == 0) { mSwipeRefreshLayout.setVisibility(View.GONE); mNoInteractionsLayout.setVisibility(View.VISIBLE); } else { if (mTools.isTablet()) { int spanCount = (response.length() == 1) ? 1 : 2; mRecyclerView.setLayoutManager( new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL)); } mRecyclerView.setAdapter(new InteractionsCardsAdapter(mContext, mProgressBar, response)); ContentValues contentValues = new ContentValues(); contentValues.put(InteractionsSQLiteHelper.COLUMN_STRING, string); SQLiteDatabase sqLiteDatabase = new InteractionsSQLiteHelper(mContext) .getWritableDatabase(); sqLiteDatabase.delete(InteractionsSQLiteHelper.TABLE, InteractionsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(string) + " COLLATE NOCASE", null); sqLiteDatabase.insert(InteractionsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mProgressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); mTools.showToast(getString(R.string.interactions_cards_something_went_wrong), 1); finish(); Log.e("InteractionsCards", error.toString()); } }); requestQueue.add(jsonArrayRequest); } catch (Exception e) { Log.e("InteractionsCards", Log.getStackTraceString(e)); } }
From source file:com.android.exchange.EasOutboxService.java
/** * Send a single message via EAS//from www . ja v a 2 s.c o m * Note that we mark messages SEND_FAILED when there is a permanent failure, rather than an * IOException, which is handled by SyncManager with retries, backoffs, etc. * * @param cacheDir the cache directory for this context * @param msgId the _id of the message to send * @throws IOException */ int sendMessage(File cacheDir, long msgId) throws IOException, MessagingException { int result = EmailServiceStatus.SUCCESS; sendCallback(msgId, null, EmailServiceStatus.IN_PROGRESS); File tmpFile = File.createTempFile("eas_", "tmp", cacheDir); // Write the output to a temporary file try { String[] cols = getRowColumns(Message.CONTENT_URI, msgId, MessageColumns.FLAGS, MessageColumns.SUBJECT); int flags = Integer.parseInt(cols[0]); String subject = cols[1]; boolean reply = (flags & Message.FLAG_TYPE_REPLY) != 0; boolean forward = (flags & Message.FLAG_TYPE_FORWARD) != 0; // The reference message and mailbox are called item and collection in EAS String itemId = null; String collectionId = null; if (reply || forward) { // First, we need to get the id of the reply/forward message cols = getRowColumns(Body.CONTENT_URI, BODY_SOURCE_PROJECTION, WHERE_MESSAGE_KEY, new String[] { Long.toString(msgId) }); if (cols != null) { long refId = Long.parseLong(cols[0]); // Then, we need the serverId and mailboxKey of the message cols = getRowColumns(Message.CONTENT_URI, refId, SyncColumns.SERVER_ID, MessageColumns.MAILBOX_KEY); if (cols != null) { itemId = cols[0]; long boxId = Long.parseLong(cols[1]); // Then, we need the serverId of the mailbox cols = getRowColumns(Mailbox.CONTENT_URI, boxId, MailboxColumns.SERVER_ID); if (cols != null) { collectionId = cols[0]; } } } } boolean smartSend = itemId != null && collectionId != null; // Write the message in rfc822 format to the temporary file FileOutputStream fileStream = new FileOutputStream(tmpFile); Rfc822Output.writeTo(mContext, msgId, fileStream, !smartSend, true); fileStream.close(); // Now, get an input stream to our temporary file and create an entity with it FileInputStream inputStream = new FileInputStream(tmpFile); InputStreamEntity inputEntity = new InputStreamEntity(inputStream, tmpFile.length()); // Create the appropriate command and POST it to the server String cmd = "SendMail&SaveInSent=T"; if (smartSend) { cmd = reply ? "SmartReply" : "SmartForward"; cmd += "&ItemId=" + itemId + "&CollectionId=" + collectionId + "&SaveInSent=T"; } userLog("Send cmd: " + cmd); HttpResponse resp = sendHttpClientPost(cmd, inputEntity, SEND_MAIL_TIMEOUT); inputStream.close(); int code = resp.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { userLog("Deleting message..."); mContentResolver.delete(ContentUris.withAppendedId(Message.CONTENT_URI, msgId), null, null); result = EmailServiceStatus.SUCCESS; sendCallback(-1, subject, EmailServiceStatus.SUCCESS); } else { userLog("Message sending failed, code: " + code); boolean retrySuccess = false; if (smartSend) { userLog("Retrying without smartSend"); cmd = "SendMail&SaveInSent=T"; userLog("Send cmd: " + cmd); inputStream = new FileInputStream(tmpFile); inputEntity = new InputStreamEntity(inputStream, tmpFile.length()); resp = sendHttpClientPost(cmd, inputEntity, SEND_MAIL_TIMEOUT); inputStream.close(); code = resp.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { userLog("Deleting message..."); mContentResolver.delete(ContentUris.withAppendedId(Message.CONTENT_URI, msgId), null, null); result = EmailServiceStatus.SUCCESS; sendCallback(-1, subject, EmailServiceStatus.SUCCESS); retrySuccess = true; } } if (!retrySuccess) { userLog("Message sending failed, code: " + code); ContentValues cv = new ContentValues(); cv.put(SyncColumns.SERVER_ID, SEND_FAILED); Message.update(mContext, Message.CONTENT_URI, msgId, cv); // We mark the result as SUCCESS on a non-auth failure since the message itself // is already marked failed and we don't want to stop other messages from // trying to send. if (isAuthError(code)) { result = EmailServiceStatus.LOGIN_FAILED; } else { result = EmailServiceStatus.SUCCESS; } sendCallback(msgId, null, result); } } } catch (IOException e) { // We catch this just to send the callback sendCallback(msgId, null, EmailServiceStatus.CONNECTION_ERROR); throw e; } finally { // Clean up the temporary file if (tmpFile.exists()) { tmpFile.delete(); } } return result; }
From source file:com.example.diego.sunshine.FetchWeatherTask.java
private Long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); Long existingId = getLocationIdByLocationSetting(locationSetting); if (existingId == null) { Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_LON, lon); Uri locationInsertUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues);//from www. j a v a 2s. c o m return ContentUris.parseId(locationInsertUri); } else { return existingId; } }
From source file:com.example.cmput301.model.DatabaseManager.java
private void addTask_LocaleTable(Task task) { ContentValues cv = new ContentValues(); cv.put(StringRes.COL_ID, task.getId()); try {/* w ww .ja va 2 s . c o m*/ cv.put(StringRes.COL_CONTENT, task.toJson().toString()); } catch (JSONException e) { e.printStackTrace(); } db.insert(StringRes.LOCAL_TASK_TABLE_NAME, StringRes.COL_ID, cv); }
From source file:com.groupe1.miage.ujf.tracestaroute.FetchTrackTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from w w w .j a va 2 s .c o m * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String cityName, double lat, double lon) { long locationId; // On regarde si la location avec nom de ville, x et y existe dja Cursor locationCursor = mContext.getContentResolver().query(TrackContract.LocationEntry.CONTENT_URI, new String[] { TrackContract.LocationEntry._ID }, TrackContract.LocationEntry.COLUMN_LOC_CITY + " = ? AND " + TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT + " = ? AND " + TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG + " = ?", new String[] { cityName, String.valueOf(lat), String.valueOf(lon) }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(TrackContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { //Cration du lieu ContentValues locationValues = new ContentValues(); //Ajout des informations locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_CITY, cityName); locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT, lat); locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG, lon); //Insertion dans la BD Uri insertedUri = mContext.getContentResolver().insert(TrackContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:com.seneca.android.senfitbeta.DbHelper.java
public void addUsers(String email, String password) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_EMAIL, email); values.put(COLUMN_PASS, password);/*from w w w. ja v a 2s .c om*/ long id = db.insert(USER_TABLE, null, values); db.close(); }
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 . ja 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 // 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; }
From source file:com.seneca.android.senfitbeta.DbHelper.java
public void insertImg(int id, String link) { Log.d("INSERT IMGDB", "Inserting images..."); SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(IMG_ID, id); values.put(LINK, link);//from w w w . j a v a 2s.c om long info = db.insert(RIP_TABLE, null, values); }