List of usage examples for android.content ContentValues ContentValues
private ContentValues(Parcel in)
From source file:com.github.gw2app.events.Gw2StaticData.java
private void _update_map_names() { if (Gw2JSONDownloader.internetAvailable(mContext)) { String result = Gw2JSONDownloader.downloadJSON(Gw2JSONDownloader.event_map_names_url); SQLiteDatabase db = mDBHelper.getWritableDatabase(); try {/*from w ww .java2 s.c o m*/ JSONArray jsData; jsData = new JSONArray(result); for (int i = 0; i < jsData.length(); i++) { JSONObject obj = jsData.getJSONObject(i); Integer id = obj.getInt("id"); String name = obj.getString("name"); ContentValues row = new ContentValues(2); row.put("_id", id); row.put("name", name); if (db != null) { db.insert(Gw2DB.MAP_NAMES_TABLE, null, row); } } } catch (JSONException e) { e.printStackTrace(); } } else { //TODO: Throw exception. } }
From source file:com.pti.mates.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w ww . j a v a 2 s .com*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); //sendNotification("Estem fent HandleIntent"); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { //sendNotification("Message type correcte"); // This loop represents the service doing some work. String type = intent.getStringExtra("type"); if (type.equals("message")) { String msg = intent.getStringExtra("data"); String senderid = intent.getStringExtra("sender"); String receiverid = intent.getStringExtra("receiver"); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal()); values.put(DataProvider.COL_MESSAGE, msg); values.put(DataProvider.COL_SENDERFBID, senderid); values.put(DataProvider.COL_RECEIVERFBID, receiverid); getApplicationContext().getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values); if (Common.isNotify()) { /*Cursor c = getApplicationContext().getContentResolver().query(DataProvider.CONTENT_URI_PROFILE, null, DataProvider.COL_FBID + "=" + senderid, null, null); int index = c.getColumnIndex(DataProvider.COL_NAME); String sendername; if (index != -1) { sendername = c.getString(index); } else { sendername = "name not available"; } sendNotificationChat("New message from " + sendername,senderid);*/ sendNotificationChat("New message", senderid); } } else if (type.equals("mate")) { //extreure info de la persona necessaria per crear el xat (insertar a la base de dades un nou perfil) //si fa falta cridar la activity per mostrar la info. (perfilActivity??) String userdatajson = intent.getStringExtra("data"); String fbid = getInfoFromJson(userdatajson, "id"); String name = getInfoFromJson(userdatajson, "name"); Log.d("Mate intent service", "fbid = " + fbid + " name = " + name); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_NAME, name); values.put(DataProvider.COL_FBID, fbid); getApplication().getContentResolver().insert(DataProvider.CONTENT_URI_PROFILE, values); sendNotificationMate("New Mate with " + name); } } /*else { String msg = intent.getExtras().toString(); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); String senderid = intent.getStringExtra("sender"); String receiverid = intent.getStringExtra("receiver"); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal()); values.put(DataProvider.COL_MESSAGE, msg); values.put(DataProvider.COL_SENDERFBID, senderid); values.put(DataProvider.COL_RECEIVERFBID, receiverid); getApplicationContext().getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values); if (Common.isNotify()) { sendNotification("New message"); } }*/ } else { //sendNotification("Extras empty"); } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
public static void insertAvatarBlob(ContentResolver resolver, Uri updateUri, long providerId, long accountId, byte[] data, String hash, String contact) { ContentValues values = new ContentValues(3); values.put(Imps.Avatars.DATA, data); values.put(Imps.Avatars.CONTACT, contact); values.put(Imps.Avatars.PROVIDER, providerId); values.put(Imps.Avatars.ACCOUNT, accountId); values.put(Imps.Avatars.HASH, hash); resolver.insert(updateUri, values);/* www.ja v a 2s . c om*/ }
From source file:at.bitfire.ical4android.AndroidTaskList.java
public static AndroidTaskList[] find(Account account, TaskProvider provider, AndroidTaskListFactory factory, String where, String whereArgs[]) throws CalendarStorageException { List<AndroidTaskList> taskLists = new LinkedList<>(); try {/*from www. ja v a 2s . c o m*/ @Cleanup Cursor cursor = provider.client.query(syncAdapterURI(provider.taskListsUri(), account), null, null, null, null); while (cursor != null && cursor.moveToNext()) { ContentValues values = new ContentValues(cursor.getColumnCount()); DatabaseUtils.cursorRowToContentValues(cursor, values); AndroidTaskList taskList = factory.newInstance(account, provider, values.getAsLong(TaskLists._ID)); taskList.populate(values); taskLists.add(taskList); } } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query task list by ID", e); } return taskLists.toArray(factory.newArray(taskLists.size())); }
From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { ContentValues values;/*from w w w . j a va 2 s .c o m*/ if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } String table = null; String nullableCol = null; switch (sUriMatcher.match(uri)) { case ITEM: table = TABLE_NAME; break; default: new RuntimeException("Invalid URI for inserting: " + uri); } SQLiteDatabase db = dbHelper.getWritableDatabase(); long rowId = db.insert(table, nullableCol, values); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(uri, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
From source file:com.github.gw2app.events.Gw2StaticData.java
private void _update_world_names() { if (Gw2JSONDownloader.internetAvailable(mContext)) { String result = Gw2JSONDownloader.downloadJSON(Gw2JSONDownloader.event_world_names_url); SQLiteDatabase db = mDBHelper.getWritableDatabase(); try {/* w w w .j a v a2 s .c om*/ JSONArray jsData; jsData = new JSONArray(result); for (int i = 0; i < jsData.length(); i++) { JSONObject obj = jsData.getJSONObject(i); Integer id = obj.getInt("id"); String name = obj.getString("name"); ContentValues row = new ContentValues(2); row.put("_id", id); row.put("name", name); if (db != null) { db.insert(Gw2DB.WORLD_NAMES_TABLE, null, row); } } } catch (JSONException e) { e.printStackTrace(); } } else { //TODO: Throw Exception. } }
From source file:li.barter.chat.ChatProcessTask.java
/** * Save a local message in the database, and give a callback to make the * chat send request once it is saved/*from ww w . ja v a 2 s . c o m*/ */ private void saveMessageAndCallback() { try { final JSONObject messageJson = new JSONObject(mMessage); final String senderId = JsonUtils.readString(messageJson, HttpConstants.SENDER_ID, true, true); final String sentAtTime = JsonUtils.readString(messageJson, HttpConstants.SENT_AT, true, true); final String receiverId = JsonUtils.readString(messageJson, HttpConstants.RECEIVER_ID, true, true); final String messageText = JsonUtils.readString(messageJson, HttpConstants.MESSAGE, true, true); final String chatId = Utils.generateChatId(receiverId, senderId); final ContentValues chatValues = new ContentValues(7); chatValues.put(DatabaseColumns.CHAT_ID, chatId); chatValues.put(DatabaseColumns.SENDER_ID, senderId); chatValues.put(DatabaseColumns.RECEIVER_ID, receiverId); chatValues.put(DatabaseColumns.MESSAGE, messageText); chatValues.put(DatabaseColumns.TIMESTAMP, sentAtTime); chatValues.put(DatabaseColumns.SENT_AT, sentAtTime); chatValues.put(DatabaseColumns.CHAT_STATUS, ChatStatus.SENDING); chatValues.put(DatabaseColumns.TIMESTAMP_EPOCH, mMessageDateFormatter.getEpoch(sentAtTime)); chatValues.put(DatabaseColumns.TIMESTAMP_HUMAN, mMessageDateFormatter.getOutputTimestamp(sentAtTime)); final long insertRowId = DBInterface.insert(TableChatMessages.NAME, null, chatValues, true); if (insertRowId >= 0) { //Update or insert the chats table final ContentValues values = new ContentValues(7); values.put(DatabaseColumns.CHAT_ID, chatId); values.put(DatabaseColumns.LAST_MESSAGE_ID, insertRowId); values.put(DatabaseColumns.CHAT_TYPE, ChatType.PERSONAL); values.put(DatabaseColumns.TIMESTAMP, sentAtTime); try { values.put(DatabaseColumns.TIMESTAMP_HUMAN, mChatDateFormatter.getOutputTimestamp(sentAtTime)); values.put(DatabaseColumns.TIMESTAMP_EPOCH, mChatDateFormatter.getEpoch(sentAtTime)); } catch (ParseException e) { //Shouldn't happen } values.put(DatabaseColumns.USER_ID, receiverId); Logger.v(TAG, "Updating chats for Id %s", chatId); final int updateCount = DBInterface.update(TableChats.NAME, values, CHAT_SELECTION, new String[] { chatId }, true); if (updateCount == 0) { //Insert the chat message DBInterface.insert(TableChats.NAME, null, values, true); } //After finishing the local chat insertion, give a callback to do the actual network call mSendChatCallback.sendChat(mMessage, insertRowId); } } catch (JSONException e) { Logger.e(TAG, e, "Invalid message json"); } catch (ParseException e) { Logger.e(TAG, e, "Invalid timestamp"); } }
From source file:com.manning.androidhacks.hack023.provider.TodoContentProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { ContentValues values;//from w ww . ja v a2 s.c o m if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } String table = null; String nullableCol = null; switch (sUriMatcher.match(uri)) { case TODO: table = TODO_TABLE_NAME; nullableCol = COLUMN_TITLE; break; default: new RuntimeException("Invalid URI for inserting: " + uri); } SQLiteDatabase db = dbHelper.getWritableDatabase(); long rowId = db.insert(table, nullableCol, values); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(uri, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
From source file:com.example.android.notepad.CMNotesProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { // Validate the requested uri if (sUriMatcher.match(uri) != NOTES) { throw new IllegalArgumentException("Unknown URI " + uri); }//from w w w . ja v a 2 s .c o m ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } Long now = Long.valueOf(System.currentTimeMillis()); // Make sure that the fields are all set if (values.containsKey(NotePad.Notes.CREATED_DATE) == false) { values.put(NotePad.Notes.CREATED_DATE, now); } if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false) { values.put(NotePad.Notes.MODIFIED_DATE, now); } if (values.containsKey(NotePad.Notes.TITLE) == false) { Resources r = Resources.getSystem(); values.put(NotePad.Notes.TITLE, r.getString(android.R.string.untitled)); } if (values.containsKey(NotePad.Notes.NOTE) == false) { values.put(NotePad.Notes.NOTE, ""); } CMAdapter cmadapter = new CMAdapter(); // for the moment, use time for the key String key = System.currentTimeMillis() + ""; String new_key = cmadapter.updateValue(key, values); if (new_key != null) { System.out.println("Set key: " + key + ", got key: " + new_key); Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, Long.parseLong(new_key)); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } // SQLiteDatabase db = mOpenHelper.getWritableDatabase(); // long rowId = db.insert(NOTES_TABLE_NAME, Notes.NOTE, values); // if (rowId > 0) { // Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, rowId); // getContext().getContentResolver().notifyChange(noteUri, null); // return noteUri; // } throw new SQLException("Failed to insert row into " + uri); }
From source file:at.bitfire.davdroid.resource.LocalCollection.java
/** * Finds new resources (resources which haven't been uploaded yet). * New resources are 1) dirty, and 2) don't have an ETag yet. * Only records matching sqlFilter will be returned. * //from w ww . j a va 2 s.c o m * @return IDs of new resources * @throws LocalStorageException when the content provider couldn't be queried */ public long[] findNew() throws LocalStorageException { String where = entryColumnDirty() + "=1 AND " + entryColumnETag() + " IS NULL"; if (entryColumnParentID() != null) where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId()); if (sqlFilter != null) where += " AND (" + sqlFilter + ")"; try { @Cleanup Cursor cursor = providerClient.query(entriesURI(), new String[] { entryColumnID() }, where, null, null); if (cursor == null) throw new LocalStorageException("Couldn't query new records"); long[] fresh = new long[cursor.getCount()]; for (int idx = 0; cursor.moveToNext(); idx++) { long id = cursor.getLong(0); // new record: we have to generate UID + remote file name for uploading T resource = findById(id, false); resource.initialize(); // write generated UID + remote file name into database ContentValues values = new ContentValues(2); values.put(entryColumnUID(), resource.getUid()); values.put(entryColumnRemoteName(), resource.getName()); providerClient.update(ContentUris.withAppendedId(entriesURI(), id), values, null, null); fresh[idx] = id; } return fresh; } catch (RemoteException ex) { throw new LocalStorageException(ex); } }