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:fr.shywim.antoinedaniel.utils.Utils.java

public static boolean prepareDownloadFromCdn(Context context, String soundName, String imageName,
        String description, String link, int version, boolean force) throws IOException {
    String extImgPath = context.getExternalFilesDir(null) + "/img/";
    String extSndPath = context.getExternalFilesDir(null) + "/snd/";

    File sndDir = new File(context.getExternalFilesDir(null) + "/snd");
    if (!sndDir.exists())
        if (!sndDir.mkdirs())
            return false;
    File imgDir = new File(context.getExternalFilesDir(null) + "/img");
    if (!imgDir.exists())
        if (!imgDir.mkdirs())
            return false;

    File file = new File(extSndPath + soundName + ".ogg");
    if (!downloadFileFromCdn(context, file, soundName, "snd/", ".ogg", force)) {
        //noinspection ResultOfMethodCallIgnored
        file.delete();/*from www.j av  a  2  s.c  o m*/
        return false;
    }

    file = new File(extImgPath + imageName + ".jpg");
    if (!downloadFileFromCdn(context, file, imageName, "img/", ".jpg", force)) {
        //noinspection ResultOfMethodCallIgnored
        file.delete();
        return false;
    }

    Uri uri = Uri.withAppendedPath(ProviderConstants.SOUND_NAME_URI, soundName);
    ContentValues cv = new ContentValues();
    cv.put(ProviderContract.SoundEntry.COLUMN_SOUND_NAME, soundName);
    cv.put(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME, imageName);
    cv.put(ProviderContract.SoundEntry.COLUMN_DESC, description);
    cv.put(ProviderContract.SoundEntry.COLUMN_LINK, link);
    cv.put(ProviderContract.SoundEntry.COLUMN_NAME_VERSION, version);
    if (uri != null) {
        context.getContentResolver().update(uri, cv, null, null);
        return true;
    } else
        return false;
}

From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java

/**
 * Creates the content values to update a category in the database.
 *
 * @param category The category to update.
 * @return ContentValues containing updatable data.
 *//*  w  w  w . j a  v a 2 s. c o m*/
private static ContentValues createContentValuesFor(Category category) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(CategoryTable.COLUMN_SOLVED, category.isSolved());
    contentValues.put(CategoryTable.COLUMN_SCORES, Arrays.toString(category.getScores()));
    return contentValues;
}

From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java

/**
 * @see Helpers#sendMessage(Context, Collection, DbObject)
 */// w ww  .  ja va  2 s .c  o  m
@Deprecated
public static void sendIM(final Context c, final Collection<Contact> contacts, final String msg) {
    Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out");
    ContentValues values = new ContentValues();
    JSONObject obj = IMObj.json(msg);
    values.put(DbObject.JSON, obj.toString());
    String to = buildAddresses(contacts);
    values.put(DbObject.DESTINATION, to);
    values.put(DbObject.TYPE, IMObj.TYPE);
    c.getContentResolver().insert(url, values);
}

From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java

public static void updatePresence(final Context c, final int presence) {
    Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    ContentValues values = new ContentValues();
    JSONObject obj = PresenceObj.json(presence);
    values.put(DbObject.JSON, obj.toString());
    values.put(DbObject.TYPE, PresenceObj.TYPE);
    c.getContentResolver().insert(url, values);
}

From source file:cn.suishen.email.LegacyConversions.java

/**
 * Save the body part of a single attachment, to a file in the attachments directory.
 *//*from   w  w w  .  ja v a2 s  . c  o  m*/
public static void saveAttachmentBody(Context context, Part part, Attachment localAttachment, long accountId)
        throws MessagingException, IOException {
    if (part.getBody() != null) {
        long attachmentId = localAttachment.mId;

        InputStream in = part.getBody().getInputStream();

        File saveIn = AttachmentUtilities.getAttachmentDirectory(context, accountId);
        if (!saveIn.exists()) {
            saveIn.mkdirs();
        }
        File saveAs = AttachmentUtilities.getAttachmentFilename(context, accountId, attachmentId);
        saveAs.createNewFile();
        FileOutputStream out = new FileOutputStream(saveAs);
        long copySize = IOUtils.copy(in, out);
        in.close();
        out.close();

        // update the attachment with the extra information we now know
        String contentUriString = AttachmentUtilities.getAttachmentUri(accountId, attachmentId).toString();

        localAttachment.mSize = copySize;
        localAttachment.mContentUri = contentUriString;

        // update the attachment in the database as well
        ContentValues cv = new ContentValues();
        cv.put(AttachmentColumns.SIZE, copySize);
        cv.put(AttachmentColumns.CONTENT_URI, contentUriString);
        Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachmentId);
        context.getContentResolver().update(uri, cv, null, null);
    }
}

From source file:com.android.email_ee.LegacyConversions.java

/**
 * Save the body part of a single attachment, to a file in the attachments directory.
 *///from   w w w  . j a  va  2  s.c  om
public static void saveAttachmentBody(Context context, Part part, Attachment localAttachment, long accountId)
        throws MessagingException, IOException {
    if (part.getBody() != null) {
        long attachmentId = localAttachment.mId;

        InputStream in = part.getBody().getInputStream();

        File saveIn = AttachmentUtilities.getAttachmentDirectory(context, accountId);
        if (!saveIn.exists()) {
            saveIn.mkdirs();
        }
        File saveAs = AttachmentUtilities.getAttachmentFilename(context, accountId, attachmentId);
        saveAs.createNewFile();
        FileOutputStream out = new FileOutputStream(saveAs);
        long copySize = IOUtils.copy(in, out);
        in.close();
        out.close();

        // update the attachment with the extra information we now know
        String contentUriString = AttachmentUtilities.getAttachmentUri(accountId, attachmentId).toString();

        localAttachment.mSize = copySize;
        localAttachment.setContentUri(contentUriString);

        // update the attachment in the database as well
        ContentValues cv = new ContentValues();
        cv.put(AttachmentColumns.SIZE, copySize);
        cv.put(AttachmentColumns.CONTENT_URI, contentUriString);
        cv.put(AttachmentColumns.UI_STATE, UIProvider.AttachmentState.SAVED);
        Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachmentId);
        context.getContentResolver().update(uri, cv, null, null);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java

public static void updatePicture(final Context c, final byte[] data) {
    //fragments cause this
    if (c == null)
        return;//from w ww. j av a 2s. com
    Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    ContentValues values = new ContentValues();
    JSONObject obj = ProfilePictureObj.json(data, false);
    values.put(DbObject.JSON, obj.toString());
    values.put(DbObject.TYPE, ProfilePictureObj.TYPE);
    c.getContentResolver().insert(url, values);

    values = new ContentValues();
    values.put(MyInfo.PICTURE, data);
    c.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/my_info"), values, null,
            null);

    //todo: should be below content provider... but then all of dbidentityprovider is like this
    DBHelper dbh = new DBHelper(c);
    try {
        MyInfo.setMyPicture(dbh, data);
    } finally {
        dbh.close();
    }
    Helpers.invalidateContacts();
}

From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java

public static void sendAppFeedInvite(Context c, Collection<Contact> contacts, String feedName,
        String packageName) {//from   w ww.  j  a v a2  s. c  o m
    Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out");
    ContentValues values = new ContentValues();
    JSONObject obj = InviteToSharedAppFeedObj.json(contacts, feedName, packageName);
    values.put(DbObject.JSON, obj.toString());
    values.put(DbObject.DESTINATION, buildAddresses(contacts));
    values.put(DbObject.TYPE, InviteToSharedAppFeedObj.TYPE);
    c.getContentResolver().insert(url, values);
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

protected static void saveFetch(Context context, PublicScript script, String trollId, String uuid,
        String status) {//from   www  . ja va2 s.  co m

    String format = "Saving fetch for category %s (script=%s) and troll=%s";
    String message = String.format(format, script.category, script, trollId);
    Log.d(TAG, message);

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getWritableDatabase();

    ContentValues values = new ContentValues(2);
    long now = System.currentTimeMillis();
    values.put(MhDlaSQLHelper.SCRIPTS_END_DATE_COLUMN, now);
    values.put(MhDlaSQLHelper.SCRIPTS_STATUS_COLUMN, status);

    String whereClause = String.format("%s = ?", MhDlaSQLHelper.SCRIPTS_ID_COLUMN);
    database.update(MhDlaSQLHelper.SCRIPTS_TABLE, values, whereClause, new String[] { uuid });

    database.close();
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

protected static void createFetchLog(Context context, PublicScript script, String trollId, String uuid) {

    String format = "Create fetch log for script=%s and troll=%s";
    String message = String.format(format, script, trollId);
    Log.d(TAG, message);/*from  ww  w  .  ja v  a2s.c  o m*/

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getWritableDatabase();

    ContentValues values = new ContentValues(6);
    long now = System.currentTimeMillis();
    values.put(MhDlaSQLHelper.SCRIPTS_ID_COLUMN, uuid);
    values.put(MhDlaSQLHelper.SCRIPTS_START_DATE_COLUMN, now);
    values.put(MhDlaSQLHelper.SCRIPTS_SCRIPT_COLUMN, script.name());
    values.put(MhDlaSQLHelper.SCRIPTS_CATEGORY_COLUMN, script.category.name());
    values.put(MhDlaSQLHelper.SCRIPTS_TROLL_COLUMN, trollId);
    values.put(MhDlaSQLHelper.SCRIPTS_STATUS_COLUMN, "PENDING");

    database.insert(MhDlaSQLHelper.SCRIPTS_TABLE, null, values);

    database.close();
}