List of usage examples for android.content ContentResolver insert
public final @Nullable Uri insert(@RequiresPermission.Write @NonNull Uri url, @Nullable ContentValues values)
From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java
public static void addDetails(ContentValues details, ArrayList<ContentValues> allReviews, Context context) { ContentResolver resolver = context.getContentResolver(); ContentValues[] a = new ContentValues[allReviews.size()]; allReviews.toArray(a);//from www.java 2s . co m Log.v(TAG, "addDetails: " + resolver.insert(MovieContract.Details.CONTENT_URI, details)); Log.v(TAG, "addDetails: " + resolver.bulkInsert(MovieContract.Review.CONTENT_URI, a)); }
From source file:com.taxicop.client.NetworkUtilities.java
/** * Attempts to authenticate the user credentials on the server. * // ww w .ja v a 2 s.c o 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: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 w w . j a v a 2s.c om 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
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID.//from www . jav a2 s . co m */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
From source file:Main.java
public static void insertPlaceholderCall(ContentResolver contentResolver, String name, String number) { ContentValues values = new ContentValues(); values.put(CallLog.Calls.NUMBER, number); values.put(CallLog.Calls.DATE, System.currentTimeMillis()); values.put(CallLog.Calls.DURATION, 0); values.put(CallLog.Calls.TYPE, CallLog.Calls.OUTGOING_TYPE); values.put(CallLog.Calls.NEW, 1);//from w w w . j ava 2 s . c o m values.put(CallLog.Calls.CACHED_NAME, name); values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0); values.put(CallLog.Calls.CACHED_NUMBER_LABEL, ""); Log.d("Call Log", "Inserting call log placeholder for " + number); contentResolver.insert(CallLog.Calls.CONTENT_URI, values); }
From source file:com.marvin.rocklock.PlaylistUtils.java
/** * Writes to a playlist given a list of new song IDs and the playlist name * * @param context the activity calling this method * @param playlistName the playlist name * @param ids the song IDs to add//from w w w .j a va2 s . c o m */ public static void writePlaylist(RockLockActivity context, String playlistName, ArrayList<String> ids) { ContentResolver resolver = context.getContentResolver(); int playlistId = getPlaylistId(context, playlistName); Uri uri; int playOrder = 1; if (playlistId == -1) { // Case: new playlist ContentValues values = new ContentValues(1); values.put(MediaStore.Audio.Playlists.NAME, playlistName); // this might be missing a members extension... uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); } else { // Case: exists playlist uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); // Get most recent play order ID from playlist, so we can append Cursor orderCursor = resolver.query(uri, new String[] { MediaStore.Audio.Playlists.Members.PLAY_ORDER }, null, null, MediaStore.Audio.Playlists.Members.PLAY_ORDER + " DESC "); if (orderCursor != null) { if (orderCursor.moveToFirst()) { playOrder = orderCursor.getInt(0) + 1; } orderCursor.close(); } } Log.d("PLAYLIST ACTIVITY", String.format("Writing playlist %s", uri)); // Add all the new tracks to the playlist. int size = ids.size(); ContentValues values[] = new ContentValues[size]; final ContentProviderClient provider = resolver.acquireContentProviderClient(uri); for (int i = 0; i < size; ++i) { values[i] = new ContentValues(); values[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, ids.get(i)); values[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, playOrder++); resolver.insert(uri, values[i]); } provider.release(); }
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 . jav a 2 s. co m resolver.insert(Sync.CONTENT_URI, contentValues); }
From source file:com.csipsimple.backup.SipProfileJson.java
private static boolean restoreSipProfile(JSONObject jsonObj, ContentResolver cr) { // Restore accounts Columns cols;//from w w w . j a v a 2s . c o m ContentValues cv; cols = getSipProfileColumns(false); cv = cols.jsonToContentValues(jsonObj); long profileId = cv.getAsLong(SipProfile.FIELD_ID); if (profileId >= 0) { Uri insertedUri = cr.insert(SipProfile.ACCOUNT_URI, cv); profileId = ContentUris.parseId(insertedUri); } // TODO : else restore call handler in private db // Restore filters cols = new Columns(Filter.FULL_PROJ, Filter.FULL_PROJ_TYPES); try { JSONArray filtersObj = jsonObj.getJSONArray(FILTER_KEY); Log.d(THIS_FILE, "We have filters for " + profileId + " > " + filtersObj.length()); for (int i = 0; i < filtersObj.length(); i++) { JSONObject filterObj = filtersObj.getJSONObject(i); // Log.d(THIS_FILE, "restoring "+filterObj.toString(4)); cv = cols.jsonToContentValues(filterObj); cv.put(Filter.FIELD_ACCOUNT, profileId); cr.insert(SipManager.FILTER_URI, cv); } } catch (JSONException e) { Log.e(THIS_FILE, "Error while restoring filters", e); } return false; }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
/** Insert a new plugin provider to the provider table. */ private static long insertProviderRow(ContentResolver cr, String providerName, String providerFullName, String signUpUrl) {/*from w w w . j a v a2 s. c o m*/ ContentValues values = new ContentValues(3); values.put(Imps.Provider.NAME, providerName); values.put(Imps.Provider.FULLNAME, providerFullName); values.put(Imps.Provider.CATEGORY, ImApp.IMPS_CATEGORY); values.put(Imps.Provider.SIGNUP_URL, signUpUrl); Uri result = cr.insert(Imps.Provider.CONTENT_URI, values); return ContentUris.parseId(result); }
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); }