Example usage for android.content ContentValues ContentValues

List of usage examples for android.content ContentValues ContentValues

Introduction

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

Prototype

public ContentValues() 

Source Link

Document

Creates an empty set of values using the default initial size

Usage

From source file:Main.java

public static ArrayList<ContentValues> getProvince(SQLiteDatabase db) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;/*from   w  w  w .  j  av  a 2  s .  c  om*/
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQXX03=?", new String[] { "1" },
            null, null, "DQX_DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("province_id", cursor.getInt(0));
            values.put("province", cursor.getString(1));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

From source file:Main.java

public static ArrayList<ContentValues> getArea(SQLiteDatabase db, int dqx_dqxx01) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;//from   w w  w  . j a  va2  s.  c o m
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02", "DQXX05" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("area_id", cursor.getInt(0));
            values.put("area", cursor.getString(1));
            values.put("full_area", cursor.getString(2));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

From source file:Main.java

public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime,
        long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) {

    ContentResolver cr = activityObj.getContentResolver();
    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, startTime);
    values.put(Events.DTEND, endTime);//  w w  w  .  j a  va  2 s . c  o  m
    values.put(Events.TITLE, title);
    values.put(Events.DESCRIPTION, description);
    values.put(Events.CALENDAR_ID, calendarId);

    if (allDay == 1) {
        values.put(Events.ALL_DAY, true);
    }

    if (hasAlarm == 1) {
        values.put(Events.HAS_ALARM, true);
    }

    //Get current timezone
    values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
    Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID());
    Uri uri = cr.insert(Events.CONTENT_URI, values);
    Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString());
    // get the event ID that is the last element in the Uri
    long eventID = Long.parseLong(uri.getLastPathSegment());

    if (hasAlarm == 1) {
        ContentValues reminders = new ContentValues();
        reminders.put(Reminders.EVENT_ID, eventID);
        reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT);
        reminders.put(Reminders.MINUTES, selectedReminderValue);

        Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders);
    }

}

From source file:Main.java

/**
 * set the value to share config/* www.  j  a  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 ArrayList<ContentValues> getCity(SQLiteDatabase db, int dqx_dqxx01, boolean municipalities) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;/*w  w  w.j  a  v a2 s  .  c  o  m*/
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        if (municipalities) {
            cursor.moveToNext();
        }
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("city_id", cursor.getInt(0));
            values.put("city", cursor.getString(1));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

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());
    }/*from  w ww.j a  v a2 s.  c om*/
    Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    return uri;
}

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 ww .  j  a  va 2  s  . c o  m*/
        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;
}

From source file:Main.java

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

    /**//from w ww  .  j a  v a  2 s .  c  o m
     * 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

@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

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;
}