List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:za.co.neilson.alarm.database.Database.java
public static long create(String name, String time, String tone, int difficulty, boolean vibrate, String[] days) {/*from w w w .j ava 2 s . c o m*/ ContentValues cv = new ContentValues(); cv.put(COLUMN_ALARM_ACTIVE, true); cv.put(COLUMN_ALARM_TIME, time); Alarm.Day[] enumDays = new Alarm.Day[days.length]; for (int i = 0; i < days.length; i++) { enumDays[i] = Alarm.Day.valueOf(days[i]); } try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; oos = new ObjectOutputStream(bos); oos.writeObject(enumDays); byte[] buff = bos.toByteArray(); cv.put(COLUMN_ALARM_DAYS, buff); } catch (Exception e) { } cv.put(COLUMN_ALARM_DIFFICULTY, difficulty); cv.put(COLUMN_ALARM_TONE, tone); cv.put(COLUMN_ALARM_VIBRATE, vibrate); cv.put(COLUMN_ALARM_NAME, name); return getDatabase().insert(ALARM_TABLE, null, cv); }
From source file:ca.frozen.curlingtv.classes.Utils.java
public static String saveImage(ContentResolver contentResolver, Bitmap source, String title, String description) {//from w ww.j av a 2 s. c om File snapshot = null; Uri url = null; try { // get/create the snapshots folder File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File rpi = new File(pictures, App.getStr(R.string.app_name)); if (!rpi.exists()) { rpi.mkdir(); } // save the file within the snapshots folder snapshot = new File(rpi, title); OutputStream stream = new FileOutputStream(snapshot); source.compress(Bitmap.CompressFormat.JPEG, 90, stream); stream.flush(); stream.close(); // create the content values ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, title); values.put(MediaStore.Images.Media.DISPLAY_NAME, title); if (description != null) { values.put(MediaStore.Images.Media.DESCRIPTION, description); } values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis()); values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(MediaStore.Images.ImageColumns.BUCKET_ID, snapshot.toString().toLowerCase(Locale.US).hashCode()); values.put(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, snapshot.getName().toLowerCase(Locale.US)); values.put("_data", snapshot.getAbsolutePath()); // insert the image into the database url = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (Exception ex) { return null; } // return the URL return (url != null) ? url.toString() : null; }
From source file:be.ac.ucl.lfsab1509.llncampus.ADE.java
/** * Start information update from ADE.//from w ww.ja va 2 s . c o m * * @param sa * Activity that launches the update thread. * @param updateRunnable * Runnable that launches the display update. * @param handler * Handler to allow the display update at the end of the execution. */ public static void runUpdateADE(final ScheduleActivity sa, final Handler handler, final Runnable updateRunnable) { final Resources r = sa.getResources(); final NotificationManager nm = (NotificationManager) sa.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder nb = new NotificationCompat.Builder(sa) .setSmallIcon(android.R.drawable.stat_sys_download) .setContentTitle(r.getString(R.string.download_from_ADE)) .setContentText(r.getString(R.string.download_progress)).setAutoCancel(true); final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(r.getString(R.string.download_from_ADE)); nm.notify(NOTIFY_ID, nb.build()); new Thread(new Runnable() { @Override public void run() { /* * Fetching of code of courses to load. */ ArrayList<Course> courses = Course.getList(); if (courses == null || courses.isEmpty()) { // Take the context of the ScheduleActivity SharedPreferences preferences = new SecurePreferences(sa); String username = preferences.getString("username", null); String password = preferences.getString("password", null); if (username != null && password != null) { UCLouvain.downloadCoursesFromUCLouvain(sa, username, password, new Runnable() { public void run() { runUpdateADE(sa, handler, updateRunnable); } }, handler); } } /* * Number of weeks. To download all the schedule, the numbers go from 0 to 51 * (0 = beginning of first semester, 51 = ending of the September exams session). */ String weeks = getWeeks(); /* * Fetching data from ADE and updating the database */ int nbError = 0; int i = 0; ArrayList<Event> events; for (Course course : courses) { i++; nb.setProgress(courses.size(), i, false); nb.setContentText(r.getString(R.string.download_for) + " " + course.getCourseCode() + "..."); nm.notify(NOTIFY_ID, nb.build()); events = ADE.getInfo(course.getCourseCode(), weeks); if (events == null) { nbError++; inboxStyle.addLine(course.getCourseCode() + " : " + r.getString(R.string.download_error)); } else { // Removing old data LLNCampus.getDatabase().delete("Horaire", "COURSE = ?", new String[] { course.getCourseCode() }); // Adding new data for (Event e : events) { ContentValues cv = e.toContentValues(); cv.put("COURSE", course.getCourseCode()); if (LLNCampus.getDatabase().insert("Horaire", cv) < 0) { nbError++; } } inboxStyle.addLine(course.getCourseCode() + " : " + events.size() + " " + r.getString(R.string.events)); nb.setStyle(inboxStyle); } } nb.setProgress(courses.size(), courses.size(), false); if (nbError == 0) { nb.setContentText(r.getString(R.string.download_done)); inboxStyle.setBigContentTitle(r.getString(R.string.download_done)); nb.setSmallIcon(android.R.drawable.stat_sys_download_done); nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else { nb.setContentText(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error) + nbError + " :/"); inboxStyle.setBigContentTitle(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error) + nbError + " :/"); nb.setSmallIcon(android.R.drawable.stat_notify_error); nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } nb.setStyle(inboxStyle); nm.notify(NOTIFY_ID, nb.build()); handler.post(updateRunnable); } }).start(); }
From source file:com.taxicop.client.NetworkUtilities.java
/** * Attempts to authenticate the user credentials on the server. * //from w w w .j a v a2s . co m * @param username * The user's username * @param password * The user's password to be authenticated * @param handler * The main UI thread's handler instance. * @param context * The caller Activity's context * @return Thread The thread on which the network mOperations are executed. */ public static Thread attemptAuth(final String username, final String password, final String country, final Handler handler, final Context context) { final Runnable runnable = new Runnable() { public void run() { String ret = "" + authenticate(username, password, country, handler, context); Log.d(TAG, "respuesta de autenticacion= " + ret); if (!ret.equals("")) { try { ContentResolver next = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(Fields.ITH, 0); values.put(Fields.ID_USR, ret); next.insert(PlateContentProvider.URI_USERS, values); Log.e(TAG, "i did it."); } catch (Exception e) { Log.e(TAG, "" + e.getMessage()); } } } }; return NetworkUtilities.performOnBackgroundThread(runnable); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void setDirtyContacts(Context mContext) { // for testing ContentResolver cr = mContext.getContentResolver(); Uri uri = ContactsContract.RawContacts.CONTENT_URI; ContentValues values = new ContentValues(); values.put(ContactsContract.RawContacts.DIRTY, 1); int num = cr.update(uri, values, null, null); Log.i("ContactManager", "Resetting " + num + " dirty on contacts"); }
From source file:net.peterkuterna.android.apps.devoxxsched.util.SyncUtils.java
public static void updateLocalMd5(ContentResolver resolver, String url, String md5) { final String syncId = Sync.generateSyncId(url); final ContentValues contentValues = new ContentValues(); Log.d("SyncUtils", "syncId = " + syncId); Log.d("SyncUtils", "url = " + url); Log.d("SyncUtils", "md5 = " + md5); contentValues.put(Sync.URI_ID, syncId); contentValues.put(Sync.URI, url); contentValues.put(Sync.MD5, md5);//from w w w.j a v a2 s.co m resolver.insert(Sync.CONTENT_URI, contentValues); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void updateBook(JSONObject book, Context context) throws JSONException { int sourceId = book.getInt("sourceId"), groupId = book.getInt("groupId"); Log.i(tag, "updateBook, sourceId: " + sourceId + ", contactId: " + groupId); ContentResolver cr = context.getContentResolver(); Uri uri = ContactsContract.Groups.CONTENT_URI; ContentValues values = new ContentValues(); values.put(ContactsContract.Groups.SOURCE_ID, sourceId); int rows = cr.update(uri, values, ContactsContract.Groups._ID + " = " + groupId, null); Log.i(tag, rows + " rows updated"); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void updateGroup(JSONObject group, Context context) throws JSONException { int sourceId = group.getInt("sourceId"), groupId = group.getInt("groupId"); Log.i(tag, "updateGroup, sourceId: " + sourceId + ", groupId: " + groupId); ContentResolver cr = context.getContentResolver(); Uri uri = ContactsContract.Groups.CONTENT_URI; ContentValues values = new ContentValues(); values.put(ContactsContract.Groups.SOURCE_ID, sourceId); int rows = cr.update(uri, values, ContactsContract.Groups._ID + " = " + groupId, null); Log.i(tag, "updated " + rows + " rows to sourceId: " + sourceId); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void resetDirtyGroups(Context ctx) { ContentResolver cr = ctx.getContentResolver(); ContentValues values = new ContentValues(); values.put(ContactsContract.Groups.DIRTY, "0"); int num = cr.update(ContactsContract.Groups.CONTENT_URI, values, null, null); Log.i(tag, "Updated " + num + " groups to dirty = 0"); num = cr.delete(SyncManager.addCallerIsSyncAdapterParameter(Groups.CONTENT_URI), Groups.DELETED + " = 1 " + " and " + Groups.ACCOUNT_TYPE + " = ? ", new String[] { Constants.ACCOUNT_TYPE }); Log.i(tag, "Deleted " + num + " groups"); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void updateNameOfExistingContact(Context context, Name ContactName, long rawContactId) { Log.i(tag, ContactName + " added"); ContentValues values = new ContentValues(); values.put(StructuredName.RAW_CONTACT_ID, rawContactId); values.put(StructuredName.PREFIX, ContactName.prefix); values.put(StructuredName.GIVEN_NAME, ContactName.given); values.put(StructuredName.MIDDLE_NAME, ContactName.middle); values.put(StructuredName.FAMILY_NAME, ContactName.family); values.put(StructuredName.SUFFIX, ContactName.suffix); values.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); context.getContentResolver().insert(SyncManager.addCallerIsSyncAdapterParameter(Data.CONTENT_URI), values); }