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

@SuppressLint("SimpleDateFormat")
public static Uri launchActivityForResult(Activity activity, Intent intent, int requestCode) {
    SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
    String filename = timeStampFormat.format(new Date());
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, filename);
    Uri photoUri = activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    activity.startActivityForResult(intent, requestCode);
    return photoUri;
}

From source file:Main.java

private static void insertDepartment(SQLiteDatabase db, String name, double coordinateX, double coordinateY,
        String city, String address, String[] telephoneNumbers, String workingHours) {
    ContentValues valuesDepartment = new ContentValues();
    valuesDepartment.put("NAME", name);
    valuesDepartment.put("COORDINATE_X", coordinateX);
    valuesDepartment.put("COORDINATE_Y", coordinateY);
    valuesDepartment.put("CITY", city);
    valuesDepartment.put("ADDRESS", address);
    valuesDepartment.put("WORKING_HOURS", workingHours);
    long idInsertedDepartment = db.insert("DEPARTMENT", null, valuesDepartment);
    for (String number : telephoneNumbers) {
        ContentValues valuesNumbers = new ContentValues();
        valuesNumbers.put("DEPARTMENT_ID", idInsertedDepartment);
        valuesNumbers.put("TELEPHONE", number);
        db.insert("TELEPHONE", null, valuesNumbers);
    }/* w  w  w .  j ava2s  . c o  m*/
}

From source file:Main.java

public static ContentValues makeContentValues(long eventId, long begin, long end, long alarmTime, int minutes) {
    ContentValues values = new ContentValues();
    values.put(CalendarAlerts.EVENT_ID, eventId);
    values.put(CalendarAlerts.BEGIN, begin);
    values.put(CalendarAlerts.END, end);
    values.put(CalendarAlerts.ALARM_TIME, alarmTime);
    long currentTime = System.currentTimeMillis();
    values.put(CalendarAlerts.CREATION_TIME, currentTime);
    values.put(CalendarAlerts.RECEIVED_TIME, 0);
    values.put(CalendarAlerts.NOTIFY_TIME, 0);
    values.put(CalendarAlerts.STATE, CalendarAlerts.STATE_SCHEDULED);
    values.put(CalendarAlerts.MINUTES, minutes);
    return values;
}

From source file:Main.java

public static void addToMediaStorePlaylist(ContentResolver resolver, int audioId, long playlistId) {
    String[] cols = new String[] { "count(*)" };
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
    Cursor cur = resolver.query(uri, cols, null, null, null);
    cur.moveToFirst();/*w  ww.j  a  v  a2  s  .c  o m*/
    final int base = cur.getInt(0);
    cur.close();
    ContentValues values = new ContentValues();
    values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
    values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
    resolver.insert(uri, values);

}

From source file:Main.java

/**
 * set the value to share config/*from  w  w w  . ja v  a  2 s.c o  m*/
 * @param context context 
 * @param key key of the config
 * @param value value of the config
 */
public static void set(Context context, String key, String value) {
    ContentValues values = new ContentValues();
    values.put("key", key);
    values.put("value", value);
    try {
        context.getContentResolver().insert(CONTENT_URI, values);
    } catch (IllegalArgumentException e1) {
    } catch (Exception e) {
        Log.e("AspShareUtil", "Error while set", e);
    }
}

From source file:Main.java

public static void addCallToLog(ContentResolver contentResolver, String number, long duration, int type,
        long time) {

    ContentValues values = new ContentValues();

    values.put(Calls.NUMBER, number);

    values.put(Calls.DATE, time);//w  w w . j  a  va  2  s  .co  m

    values.put(Calls.DURATION, duration);

    values.put(Calls.TYPE, type);

    values.put(Calls.NEW, 1);

    values.put(Calls.CACHED_NAME, "");

    values.put(Calls.CACHED_NUMBER_TYPE, 0);

    values.put(Calls.CACHED_NUMBER_LABEL, "");

    contentResolver.insert(Calls.CONTENT_URI, values);

}

From source file:Main.java

private static void insertDrink(SQLiteDatabase db, String name, String description, int resourceId) { //this method was created to
    ContentValues drinkValues = new ContentValues(); //... insert several drink rows
    drinkValues.put("NAME", name);
    drinkValues.put("DESCRIPTION", description);
    drinkValues.put("image_id", resourceId);
    db.insert("DRINK", null, drinkValues);
}

From source file:Main.java

public static Uri pathToContentUri(Context context, String imagePath) {
    Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { "_id" },
            "_data=? ", new String[] { imagePath }, null);
    if (cursor != null && cursor.moveToFirst()) {
        int imageFile1 = cursor.getInt(cursor.getColumnIndex("_id"));
        Uri values1 = Uri.parse("content://media/external/images/media");
        return Uri.withAppendedPath(values1, "" + imageFile1);
    } else {//from  w w w.  j a  v a  2  s.  co m
        File imageFile = new File(imagePath);
        if (imageFile.exists()) {
            ContentValues values = new ContentValues();
            values.put("_data", imagePath);
            Uri baseUri = Media.EXTERNAL_CONTENT_URI;
            return context.getContentResolver().insert(baseUri, values);
        } else {
            return null;
        }
    }
}

From source file:Main.java

public static void insertStudent(final SQLiteDatabase database, final String id, final String name) {
    final ContentValues courseValues;

    courseValues = new ContentValues();
    courseValues.put(STUDENT_NUMBER, id);
    courseValues.put(STUDENT_NAME, name);
    database.insert(STUDENT_TABLE, null, courseValues);
}

From source file:Main.java

public static void insertStudentCourse(final SQLiteDatabase database, final String id,
        final String courseName) {
    final ContentValues courseValues;

    courseValues = new ContentValues();
    courseValues.put(STUDENT_NUMBER, id);
    courseValues.put(COURSE_NAME, courseName);
    database.insert(STU_COUR_TABLE, null, courseValues);
}