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.manning.androidhacks.hack043.service.SQLContentProviderService.java

@Override
protected void onHandleIntent(Intent intent) {
    Builder builder = null;/*from  w w w .  ja v a2 s.  c  om*/
    ContentResolver contentResolver = getContentResolver();
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

    builder = ContentProviderOperation.newDelete(MySQLContentProvider.CONTENT_URI);
    operations.add(builder.build());

    for (int i = 1; i <= 100; i++) {
        ContentValues cv = new ContentValues();
        cv.put(MySQLContentProvider.COLUMN_TEXT, "" + i);

        builder = ContentProviderOperation.newInsert(MySQLContentProvider.CONTENT_URI);
        builder.withValues(cv);

        operations.add(builder.build());
    }

    try {
        contentResolver.applyBatch(MySQLContentProvider.AUTHORITY, operations);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't apply batch: " + e.getMessage());
    } catch (OperationApplicationException e) {
        Log.e(TAG, "Couldn't apply batch: " + e.getMessage());
    }

}

From source file:com.manning.androidhacks.hack043.service.BatchService.java

@Override
protected void onHandleIntent(Intent intent) {
    Builder builder = null;//from w  w  w  . ja  v  a  2  s .  c  om
    ContentResolver contentResolver = getContentResolver();
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

    builder = ContentProviderOperation.newDelete(BatchNumbersContentProvider.CONTENT_URI);
    operations.add(builder.build());

    for (int i = 1; i <= 100; i++) {
        ContentValues cv = new ContentValues();
        cv.put(NoBatchNumbersContentProvider.COLUMN_TEXT, "" + i);

        builder = ContentProviderOperation.newInsert(BatchNumbersContentProvider.CONTENT_URI);
        builder.withValues(cv);

        operations.add(builder.build());
    }

    try {
        contentResolver.applyBatch(BatchNumbersContentProvider.AUTHORITY, operations);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't apply batch: " + e.getMessage());
    } catch (OperationApplicationException e) {
        Log.e(TAG, "Couldn't apply batch: " + e.getMessage());
    }

}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.FeedAnchorObj.java

@Override
public void afterDbInsertion(Context context, DbObj obj) {
    Uri feedUri = obj.getContainingFeed().getUri();
    String parentFeedName = obj.getJson().optString(PARENT_FEED_NAME);
    if (parentFeedName == null) {
        Log.e(TAG, "anchor for feed, but no parent given");
        return;/* w  w w.j a  va 2  s. co m*/
    }

    Maybe<Group> parentGroup = Group.forFeedName(context, parentFeedName);
    if (!parentGroup.isKnown()) {
        Log.e(TAG, "No parent entry found for " + parentFeedName);
        return;
    }
    Long parentId = -1l;
    try {
        parentId = parentGroup.get().id;
    } catch (NoValError e) {
    }

    String feedName = feedUri.getLastPathSegment();
    Log.d(TAG, "Updating parent_feed_id for " + feedName);
    DBHelper mHelper = DBHelper.getGlobal(context);
    ContentValues cv = new ContentValues();
    cv.put(Group.PARENT_FEED_ID, parentId);
    mHelper.getWritableDatabase().update(Group.TABLE, cv, Group.FEED_NAME + "=?", new String[] { feedName });
    mHelper.close();
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.ProfileObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String name = obj.optString(NAME);
    String id = Long.toString(from.id);
    ContentValues values = new ContentValues();
    values.put(Contact.NAME, name);
    context.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), values,
            "_id=?", new String[] { id });
}

From source file:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java

@Override
public void setAutoSelect(AutoSelectSet autoSelectSet) {
    final String TABLE = DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME;

    SQLiteDatabase database = this.database.openDatabase(true);

    this.database.deleteAllRowsWithLoginSetKey(database, TABLE);

    ContentValues values = new ContentValues();
    values.put(DatabaseCreateConstants.TABLE_LOGINSET_KEY, this.database.getLoginSetKeyForTable());
    values.put(DatabaseAutoSelectConstants.ENABLED, autoSelectSet.isEnabled());
    values.put(DatabaseAutoSelectConstants.TYPE, autoSelectSet.getAutoSelectType());
    values.put(DatabaseAutoSelectConstants.VALUE, autoSelectSet.getAutoSelectValue());

    database.beginTransaction();/*from w  w w. j a  v  a  2s.  co m*/

    this.database.insert(database, TABLE, values);

    database.setTransactionSuccessful();
    database.endTransaction();
    this.database.closeDatabase(database);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.ProfilePictureObj.java

public boolean handleObjFromNetwork(Context context, Contact from, JSONObject obj) {
    byte[] data = FastBase64.decode(obj.optString(DATA));
    boolean reply = obj.optBoolean(REPLY);

    String id = Long.toString(from.id);
    ContentValues values = new ContentValues();
    values.put(Contact.PICTURE, data);
    context.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), values,
            "_id=?", new String[] { id });
    Helpers.invalidateContacts();//from w ww. j a  va  2 s  .  c  o m

    if (reply) {
        LinkedList<Contact> contacts = new LinkedList<Contact>();
        contacts.add(from);
        Helpers.resendProfile(context, contacts, false);
    }
    return false;
}

From source file:com.liferay.alerts.callback.VoteCallback.java

@Override
public void onSuccess(JSONObject vote) {
    ToastUtil.show(_context, R.string.vote_success, true);

    try {/* w ww  .  jav  a  2  s.  co  m*/
        AlertDAO dao = AlertDAO.getInstance(_context);
        Alert alert = dao.get(_alertId);
        PollsQuestion question = alert.getPollsQuestion();

        alert.setPollsQuestion(question.toJSONObject(_choiceId));

        ContentValues values = new ContentValues();
        values.put(Alert.PAYLOAD, alert.getPayload().toString());

        dao.update(_alertId, values, true);
    } catch (Exception e) {
        Log.e(_TAG, "Could not update vote in database.", e);
    }
}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 *
 * Parse and insert PosterEntry/*from ww w.  j a v a 2s.  c  om*/
 *
 * @throws JSONException
 */
public static void parseAndInsertPosters(Context context, String jsonData, String id) throws JSONException {

    // Timestamp.
    final long currentTime = System.currentTimeMillis();

    // String to the root of JSONObject, the argument s is a String in JSON format.
    JSONObject rootObject = new JSONObject(jsonData);

    // call the rootObjet and get the key assign to String variable
    String rootObj = rootObject.get("backdrops").toString();

    // now the rootObj has the value of "backdrops" which is a JSON Array
    // then assign it as argument into JSONArray object
    JSONArray ar = new JSONArray(rootObj);
    final int arSize = ar.length();

    // Containers
    ContentValues lContentValuePoster = new ContentValues();

    // iterate for each element in the JSONArray
    for (int i = 0; i < arSize; i++) {
        // convert each element in ar into JSONOject
        // and pass the argument i which i is the index of each element
        JSONObject obj = ar.getJSONObject(i);

        // Packing into ContentValues object
        lContentValuePoster.put(ContractMovies.PosterEntry.COLUMN_MOVIE_ID, String.valueOf(id));
        lContentValuePoster.put(ContractMovies.PosterEntry.COLUMN_FILE_PATH, obj.getString("file_path"));
        lContentValuePoster.put(ContractMovies.PosterEntry.COLUMN_POSTING_TIME, currentTime);

        // Do insert now
        try {
            context.getContentResolver().insert(ContractMovies.PosterEntry.CONTENT_URI, lContentValuePoster);
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
        }
    }
}

From source file:com.liferay.alerts.model.User.java

@Override
public ContentValues toContentValues() {
    ContentValues values = new ContentValues();

    values.put(ID, _id);
    values.put(UUID, _uuid);//from w w  w . j  ava  2  s  .  c  om
    values.put(FULL_NAME, _fullName);
    values.put(PORTRAIT_ID, _portraitId);

    return values;
}

From source file:com.manning.androidhacks.hack037.MainActivity.java

public void onLoop1Click(View v) {
    if (!canWriteInExternalStorage()) {
        Toast.makeText(this, "Can't write file", Toast.LENGTH_SHORT).show();
        return;//from   w ww .j a  v  a  2 s.c o  m
    }

    Log.d("TAG", "LOOP1: " + LOOP1_PATH);
    MediaUtils.saveRaw(this, R.raw.loop1, LOOP1_PATH);

    ContentValues values = new ContentValues(5);
    values.put(Media.ARTIST, "Android");
    values.put(Media.ALBUM, "60AH");
    values.put(Media.TITLE, "hack043");
    values.put(Media.MIME_TYPE, "audio/mp3");
    values.put(Media.DATA, LOOP1_PATH);

    getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
}