Example usage for android.content ContentValues put

List of usage examples for android.content ContentValues put

Introduction

In this page you can find the example usage for android.content ContentValues put.

Prototype

public void put(String key, byte[] value) 

Source Link

Document

Adds a value to the set.

Usage

From source file:com.csipsimple.backup.Columns.java

private static void j2cvDouble(JSONObject j, ContentValues cv, String key) {
    try {//from   ww w  . j av  a 2  s.  c o  m
        double v = j.getDouble(key);
        cv.put(key, v);
    } catch (JSONException e) {
    }
}

From source file:com.csipsimple.backup.Columns.java

private static void j2cvBoolean(JSONObject j, ContentValues cv, String key) {
    try {/*  w w w  .  ja v  a2  s .co m*/
        boolean v = j.getBoolean(key);
        cv.put(key, v);
    } catch (JSONException e) {
    }
}

From source file:org.muckebox.android.net.RefreshHelper.java

public static Integer refreshTracks(long albumId) {
    try {//from  ww  w .  jav  a2s .  com
        ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(1);

        JSONArray json = ApiHelper.callApiForArray("tracks", null, new String[] { "album" },
                new String[] { Long.toString(albumId) });
        operations.ensureCapacity(operations.size() + json.length() + 1);

        operations.add(ContentProviderOperation
                .newDelete(Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS_ALBUM, Long.toString(albumId)))
                .build());

        for (int j = 0; j < json.length(); ++j) {
            JSONObject o = json.getJSONObject(j);
            ContentValues values = new ContentValues();

            values.put(TrackEntry.SHORT_ID, o.getInt("id"));
            values.put(TrackEntry.SHORT_ARTIST_ID, o.getInt("artist_id"));
            values.put(TrackEntry.SHORT_ALBUM_ID, o.getInt("album_id"));

            values.put(TrackEntry.SHORT_TITLE, o.getString("title"));

            if (!o.isNull("tracknumber"))
                values.put(TrackEntry.SHORT_TRACKNUMBER, o.getInt("tracknumber"));

            if (!o.isNull("discnumber"))
                values.put(TrackEntry.SHORT_DISCNUMBER, o.getInt("discnumber"));

            values.put(TrackEntry.SHORT_LABEL, o.getString("label"));
            values.put(TrackEntry.SHORT_CATALOGNUMBER, o.getString("catalognumber"));

            values.put(TrackEntry.SHORT_LENGTH, o.getInt("length"));
            values.put(TrackEntry.SHORT_DATE, o.getString("date"));

            operations.add(ContentProviderOperation
                    .newDelete(
                            Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS, Integer.toString(o.getInt("id"))))
                    .build());
            operations.add(
                    ContentProviderOperation.newInsert(MuckeboxProvider.URI_TRACKS).withValues(values).build());
        }

        Log.d(LOG_TAG, "Got " + json.length() + " Tracks");

        Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations);
    } catch (AuthenticationException e) {
        return R.string.error_authentication;
    } catch (SSLException e) {
        return R.string.error_ssl;
    } catch (IOException e) {
        Log.d(LOG_TAG, "IOException: " + e.getMessage());
        return R.string.error_reload_tracks;
    } catch (JSONException e) {
        return R.string.error_json;
    } catch (RemoteException e) {
        e.printStackTrace();
        return R.string.error_reload_tracks;
    } catch (OperationApplicationException e) {
        e.printStackTrace();
        return R.string.error_reload_tracks;
    }

    return null;
}

From source file:com.csipsimple.backup.Columns.java

private static void j2cvFloat(JSONObject j, ContentValues cv, String key) {
    try {//from w ww.  ja  va2 s.c  om
        float v = (float) j.getDouble(key);
        cv.put(key, v);
    } catch (JSONException e) {
    }
}

From source file:android.provider.Checkin.java

/**
 * Helper function to report a crash./*from ww w. ja v a 2s .  c  o  m*/
 *
 * @param resolver from {@link android.content.Context#getContentResolver}
 * @param crash data from {@link android.server.data.CrashData}
 * @return URI of the crash report that was added
 */
static public Uri reportCrash(ContentResolver resolver, byte[] crash) {
    try {
        // If we are in a situation where crash reports fail (such as a full disk),
        // it's important that we don't get into a loop trying to report failures.
        // So discard all crash reports for a few seconds after reporting fails.
        long realtime = SystemClock.elapsedRealtime();
        if (realtime - sLastCrashFailureRealtime < MIN_CRASH_FAILURE_RETRY) {
            Log.e(TAG, "Crash logging skipped, too soon after logging failure");
            return null;
        }

        // HACK: we don't support BLOB values, so base64 encode it.
        byte[] encoded = Base64.encodeBase64(crash);
        ContentValues values = new ContentValues();
        values.put(Crashes.DATA, new String(encoded));
        Uri uri = resolver.insert(Crashes.CONTENT_URI, values);
        if (uri == null) {
            Log.e(TAG, "Error reporting crash");
            sLastCrashFailureRealtime = SystemClock.elapsedRealtime();
        }
        return uri;
    } catch (Throwable t) {
        // To avoid an infinite crash-reporting loop, swallow all errors and exceptions.
        Log.e(TAG, "Error reporting crash: " + t);
        sLastCrashFailureRealtime = SystemClock.elapsedRealtime();
        return null;
    }
}

From source file:at.bitfire.ical4android.AndroidCalendar.java

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentProviderClient provider, ContentValues info)
        throws CalendarStorageException {
    info.put(Calendars.ACCOUNT_NAME, account.name);
    info.put(Calendars.ACCOUNT_TYPE, account.type);

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        // these values are generated by ical4android
        info.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE + ","
                + Events.AVAILABILITY_TENTATIVE);
        info.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }//from   w  w  w.  j av a2  s  .c o  m

    Log.i(TAG, "Creating local calendar: " + info.toString());
    try {
        return provider.insert(syncAdapterURI(Calendars.CONTENT_URI, account), info);
    } catch (RemoteException e) {
        throw new CalendarStorageException("Couldn't create calendar", e);
    }
}

From source file:edu.mit.mobile.android.livingpostcards.data.Card.java

/**
 * Creates a new card with a random UUID. Cards are marked DRAFT by default.
 *
 * @param cr// ww w.  ja  v  a2s  . c  om
 * @param cv
 *            initial card contents
 * @return
 */
public static Uri createNewCard(Context context, Account account, ContentValues cv) {

    JsonSyncableItem.addUuid(cv);

    cv.put(Card.COL_DRAFT, true);

    Authorable.putAuthorInformation(context, account, cv);

    final Uri card = context.getContentResolver().insert(Card.CONTENT_URI, cv);

    return card;
}

From source file:com.example.orangeweather.JSONWeatherParser.java

public static ContentValues getForecast(JSONObject jObj) throws JSONException {
    ContentValues cv = new ContentValues();
    cv.put(ForecastTags.FORECAST_DT, getInt(ForecastTags.FORECAST_DT, jObj));
    JSONObject tempObj = getObject("temp", jObj);
    cv.put(ForecastTags.FORECAST_TEMP_DAY,
            getTemperatureString(getFloat(ForecastTags.FORECAST_TEMP_DAY, tempObj)));
    cv.put(ForecastTags.FORECAST_TEMP_NIGHT,
            getTemperatureString(getFloat(ForecastTags.FORECAST_TEMP_NIGHT, tempObj)));
    JSONArray weatherObj = jObj.getJSONArray("weather");
    cv.put(ForecastTags.FORECAST_COND_MAIN,
            weatherObj.getJSONObject(0).getString(ForecastTags.FORECAST_COND_MAIN));
    return cv;/*  w  w w. j  a  v  a 2s  .  c o m*/
}

From source file:mobisocial.socialkit.musubi.DbObj.java

/**
 * Prepares ContentValues that can be delivered to Musubi's Content Provider
 * for insertion into a SocialDb feed.//from   w ww.j  a va2s  . c o  m
 */
public static ContentValues toContentValues(Uri feedUri, Long parentObjId, Obj obj) {
    ContentValues values = new ContentValues();
    values.put(DbObj.COL_TYPE, obj.getType());
    if (obj.getStringKey() != null) {
        values.put(DbObj.COL_STRING_KEY, obj.getStringKey());
    }
    if (obj.getJson() != null) {
        values.put(DbObj.COL_JSON, obj.getJson().toString());
    }
    if (obj.getIntKey() != null) {
        values.put(DbObj.COL_INT_KEY, obj.getIntKey());
    }
    if (obj.getRaw() != null) {
        values.put(DbObj.COL_RAW, obj.getRaw());
    }
    if (parentObjId != null) {
        values.put(DbObj.COL_PARENT_ID, parentObjId);
    }
    try {
        Long feedId = Long.parseLong(feedUri.getLastPathSegment());
        values.put(DbObj.COL_FEED_ID, feedId);
    } catch (Exception e) {
        throw new IllegalArgumentException("No feed id found for " + feedUri, e);
    }
    return values;
}

From source file:com.onesignal.NotificationOpenedProcessor.java

private static ContentValues newContentValuesWithConsumed() {
    ContentValues values = new ContentValues();

    boolean dismissed = intent.getBooleanExtra("dismissed", false);

    if (dismissed)
        values.put(NotificationTable.COLUMN_NAME_DISMISSED, 1);
    else//from w  w  w .  j a v  a2s.co  m
        values.put(NotificationTable.COLUMN_NAME_OPENED, 1);

    return values;
}