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:Main.java

static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception {

    File extdir = Environment.getExternalStorageDirectory();
    File tmp_top = new File(extdir, "tmp_LongText");
    if (!tmp_top.exists()) {
        if (!tmp_top.mkdir())
            throw new Exception("cannot create directory: " + tmp_top.getPath());
    }//w  w w  .  j a v  a  2 s  .c  o m
    if (!tmp_top.canWrite())
        throw new Exception("missing permission to write to " + tmp_top.getPath());

    File tmpdir;
    Random r = new Random();
    do {
        tmpdir = new File(tmp_top, String.format("%d", r.nextInt()));
    } while (tmpdir.exists());
    if (!tmpdir.mkdir())
        throw new Exception("cannot create directory: " + tmp_top.getPath());
    if (!tmpdir.canWrite())
        throw new Exception("missing permission to write to " + tmp_top.getPath());
    ContentValues v = new ContentValues();
    v.put("pid", Process.myPid());
    v.put("tmpdir", tmpdir.getPath());
    v.put("ctime", System.currentTimeMillis());
    db.insert("tmpdir", null, v);

    return tmpdir;
}

From source file:Main.java

/**
 * Update content./*from   www .j a va  2s  .  c om*/
 *
 * @param context
 *            context
 * @param sourceUri
 *            source uri
 * @param file
 *            output file
 * @return source uri
 */
public static Uri updateContent(Context context, Uri sourceUri, File file) {
    long now = System.currentTimeMillis() / MILLISEC_PER_SEC;
    final ContentValues values = new ContentValues();
    values.put(Images.Media.DATE_MODIFIED, now);
    values.put(Images.Media.DATE_ADDED, now);
    values.put(Images.Media.SIZE, file.length());
    context.getContentResolver().update(sourceUri, values, null, null);
    return sourceUri;
}

From source file:Main.java

private static boolean modifyPermission(Context context, int flag) {
    String packageName = context.getPackageName();
    try {//  www.j  av  a2  s .  c  om
        ContentValues contentValues = new ContentValues();
        contentValues.put("userAccept", Integer.valueOf(flag));
        context.getContentResolver().update(Uri.parse("content://com.lbe.security.miui.permmgr/active"),
                contentValues, "pkgName=?", new String[] { packageName });
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static ContentValues buildContentValues() {
    int colorCalendar = 0x0066CC;
    String intName = ACCOUNT_NAME + Calendar_Name;
    final ContentValues cv = new ContentValues();
    cv.put(Calendars.ACCOUNT_NAME, ACCOUNT_NAME);
    cv.put(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
    cv.put(Calendars.NAME, intName);/*from w  w  w.  ja v  a  2s  .  co  m*/
    cv.put(Calendars.CALENDAR_DISPLAY_NAME, Calendar_Name);
    cv.put(Calendars.CALENDAR_COLOR, colorCalendar);
    cv.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
    cv.put(Calendars.OWNER_ACCOUNT, ACCOUNT_NAME);
    cv.put(Calendars.VISIBLE, 1);
    cv.put(Calendars.SYNC_EVENTS, 1);
    return cv;
}

From source file:Main.java

public static void addToFacebookContact(Context mContext, ArrayList<String> contactDatas) {

    /**//from  ww  w .  j  a  v  a2  s .  c  om
     * ArrayList elements:
     * 
     * 1. Name 2. Userid 3.Username
     */

    Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);

    if (contactDatas.get(2) == null) {
        contactDatas.set(2, "Facebook name");
    }

    ArrayList<ContentValues> data = new ArrayList<ContentValues>();
    ContentValues row1 = new ContentValues();
    row1.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
    row1.put(ContactsContract.Data.DATA1, contactDatas.get(2));
    row1.put(ContactsContract.Data.DATA2, ContactsContract.CommonDataKinds.Im.TYPE_OTHER);
    row1.put(ContactsContract.Data.DATA5, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM);
    row1.put(ContactsContract.Data.DATA6, "Facebook");
    row1.put(ContactsContract.Data.DATA10, contactDatas.get(1));
    data.add(row1);

    i.putExtra(Insert.NAME, contactDatas.get(0));
    i.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);

    mContext.startActivity(i);
}

From source file:Main.java

/**
 * Add an entry to the database//from  w  w  w .  ja  v  a  2s .c o  m
 *
 * @param db
 *            pointer to database
 * @param recordLine
 *            String with a record
 *            format: yy,mm,dd,hh:mm,light,solar,consumption
 *            e.g.: "15,08,13,13:54,35000,613.456,-120.22"
 */
public static void addDay(SQLiteDatabase db, String recordLine) {

    /* Parse the string into its single values */
    String[] valuesPerLine = recordLine.split(",");

    if (valuesPerLine.length == 1) {
        return;
    }
    /** String list with hour & minute values */
    String[] hourSplit = valuesPerLine[3].split(":");

    /** ContentValues to hold the measured and calculated values to be added to the database */
    ContentValues values = new ContentValues(14);
    values.put("year", Integer.parseInt(valuesPerLine[0]));
    values.put("month", Integer.parseInt(valuesPerLine[1]));
    values.put("day", Integer.parseInt(valuesPerLine[2]));
    values.put("hour", Integer.parseInt(hourSplit[0]));
    values.put("minute", Integer.parseInt(hourSplit[1]));
    values.put("solar", Double.parseDouble(valuesPerLine[5]));
    values.put("cons", Double.parseDouble(valuesPerLine[6]));
    values.put("light", Long.parseLong(valuesPerLine[4]));

    db.insert(TABLE_NAME, null, values);
}

From source file:Main.java

public static ContentValues getContentValuesFromMap(Map<String, String> contentValues) {
    ContentValues values = new ContentValues();
    for (String s : contentValues.keySet()) {
        values.put(s, contentValues.get(s));
    }//from   ww  w. ja  v a 2 s. co m
    return values;
}

From source file:Main.java

public static Uri getPhotoUri(Context context) {
    long currentTimeMillis = System.currentTimeMillis();
    Date today = new Date(currentTimeMillis);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
    String title = dateFormat.format(today);
    String dirPath = getDirPath(context);
    String fileName = "img_capture_" + title + ".jpg";
    String path = dirPath + "/" + fileName;
    File file = new File(path);
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, title);
    values.put(MediaStore.Images.Media.DISPLAY_NAME, fileName);
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.Images.Media.DATA, path);
    values.put(MediaStore.Images.Media.DATE_TAKEN, currentTimeMillis);
    if (file.exists()) {
        values.put(MediaStore.Images.Media.SIZE, file.length());
    }/* ww w.ja va  2 s  .  c o m*/
    Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    return uri;
}

From source file:Main.java

public static void extrasVarArgsToValues(ContentValues values, String... extras) {
    for (int i = 0; i < extras.length;) {
        values.put(extras[i], extras[i + 1]);
        i += 2;// w  w  w .  ja  v  a 2s  .  co m
    }
}

From source file:Main.java

@SuppressLint("InlinedApi")
private static boolean updateGallery(Context context, Bitmap bmp, String fileNm) {
    // Insert into MediaStore.
    ContentValues values = new ContentValues();
    values.put(ImageColumns.TITLE, fileNm);
    values.put(ImageColumns.DISPLAY_NAME, fileNm);
    values.put(ImageColumns.DATE_TAKEN, System.currentTimeMillis());
    values.put(ImageColumns.MIME_TYPE, "image/jpeg");
    values.put(ImageColumns.ORIENTATION, 0);
    values.put(ImageColumns.DATA, PIC_ROOT_PATH + fileNm);
    values.put(ImageColumns.WIDTH, bmp.getWidth());
    values.put(ImageColumns.HEIGHT, bmp.getHeight());

    try {//from   w  w w.  ja  va2 s  .c om
        Uri uri = context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
        if (uri == null) {
            Log.e("storeImage", "Failed to insert MediaStore");
            return false;
        } else {
            context.sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", uri));
        }
    } catch (Exception e) {
        Log.e("storeImage", "Failed to write MediaStore", e);
        return false;
    }

    return true;
}