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:org.mariotaku.twidere.fragment.SearchFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);/* w w w . j a va 2s .c o m*/ final String query = getQuery(); if (savedInstanceState == null && !TextUtils.isEmpty(query)) { final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(), RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE); suggestions.saveRecentQuery(query, null); final ContentResolver cr = getContentResolver(); final ContentValues values = new ContentValues(); values.put(SearchHistory.QUERY, query); cr.insert(SearchHistory.CONTENT_URI, values); } }
From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java
public void addNewTodo(ContentResolver contentResolver, Todo list, int flag) { ContentValues contentValue = getTodoContentValues(list, flag); contentResolver.insert(TodoContentProvider.CONTENT_URI, contentValue); }
From source file:com.commonsware.android.constants.ConstantsFragment.java
public void onClick(DialogInterface di, int whichButton) { ContentValues values = new ContentValues(2); AlertDialog dlg = (AlertDialog) di;//from w w w .ja va2 s .c o m EditText title = dlg.findViewById(R.id.title); EditText value = dlg.findViewById(R.id.value); values.put(DatabaseHelper.TITLE, title.getText().toString()); values.put(DatabaseHelper.VALUE, value.getText().toString()); final ContentResolver cr = getActivity().getContentResolver(); new Thread() { @Override public void run() { cr.insert(Provider.Constants.CONTENT_URI, values); } }.start(); }
From source file:com.nononsenseapps.notepad.MainActivity.java
/** * Inserts a new note in the designated list * //from w w w . j a va 2s. co m * @param resolver * @param listId * @return */ public static Uri createNote(Context context, long listId, String noteText) { if (listId > -1) { ContentValues values = new ContentValues(); // Must always include list values.put(NotePad.Notes.COLUMN_NAME_LIST, listId); values.put(NotePad.Notes.COLUMN_NAME_NOTE, noteText); try { ContentResolver resolver = context.getContentResolver(); Uri uri = resolver.insert(NotePad.Notes.CONTENT_URI, values); UpdateNotifier.notifyChangeNote(context, uri); return uri; } catch (SQLException e) { return null; } } else { return null; } }
From source file:org.ale.scanner.zotero.data.BibItem.java
public void writeToDB(ContentResolver cr) { ContentValues values = toContentValues(); if (mId == NO_ID) { Uri row = cr.insert(Database.BIBINFO_URI, values); int id = Integer.parseInt(row.getLastPathSegment()); setId(id);// w w w . j av a 2 s . c om } else { cr.update(Database.BIBINFO_URI, values, BibItem._ID + "=?", new String[] { String.valueOf(mId) }); } }
From source file:com.dabay6.android.apps.carlog.ui.base.fragments.BaseEditFragment.java
/** * {@inheritDoc}//w w w. j a v a2 s .c o m */ @Override public void onPositiveButtonClick() { try { if (validator.validate()) { final ContentValues values = buildContentValues(); final ContentResolver resolver = applicationContext.getContentResolver(); if (isInsert) { resolver.insert(getUri(), values); } else { final String selection = getIdentityColumnName() + " = ?"; final String[] selectionArgs = new String[] { entityId.toString() }; resolver.update(getUri(), values, selection, selectionArgs); } clear(); onEntityEditListener.onEntitySave(); } } catch (Exception e) { Logger.error(TAG, e.getMessage(), e); } }
From source file:com.manning.androidhacks.hack043.service.NoBatchService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver contentResolver = getContentResolver(); contentResolver.delete(NoBatchNumbersContentProvider.CONTENT_URI, null, null); for (int i = 1; i <= 100; i++) { ContentValues cv = new ContentValues(); cv.put(NoBatchNumbersContentProvider.COLUMN_TEXT, "" + i); contentResolver.insert(NoBatchNumbersContentProvider.CONTENT_URI, cv); }/* w w w . j ava2 s .c o m*/ }
From source file:org.totschnig.myexpenses.provider.DbUtils.java
private static void cacheEventData() { if (ContextCompat.checkSelfPermission(MyApplication.getInstance(), Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { return;/*from ww w . j av a2s. c o m*/ } String plannerCalendarId = PrefKey.PLANNER_CALENDAR_ID.getString("-1"); if (plannerCalendarId.equals("-1")) { return; } ContentValues eventValues = new ContentValues(); ContentResolver cr = MyApplication.getInstance().getContentResolver(); //remove old cache cr.delete(TransactionProvider.EVENT_CACHE_URI, null, null); Cursor planCursor = cr.query(Template.CONTENT_URI, new String[] { DatabaseConstants.KEY_PLANID }, DatabaseConstants.KEY_PLANID + " IS NOT null", null, null); if (planCursor != null) { if (planCursor.moveToFirst()) { String[] projection = MyApplication.buildEventProjection(); do { long planId = planCursor.getLong(0); Uri eventUri = ContentUris.withAppendedId(CalendarContractCompat.Events.CONTENT_URI, planId); Cursor eventCursor = cr.query(eventUri, projection, CalendarContractCompat.Events.CALENDAR_ID + " = ?", new String[] { plannerCalendarId }, null); if (eventCursor != null) { if (eventCursor.moveToFirst()) { MyApplication.copyEventData(eventCursor, eventValues); cr.insert(TransactionProvider.EVENT_CACHE_URI, eventValues); } eventCursor.close(); } } while (planCursor.moveToNext()); } planCursor.close(); } }
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testPropertiesRestricted() throws Exception { ContentResolver r = getContext().getContentResolver(); // The test app doesn't have the permission to access properties, // so any attempt to do so should fail. try {/*from w w w .j av a2 s . c o m*/ r.insert(Checkin.Properties.CONTENT_URI, new ContentValues()); fail("SecurityException expected"); } catch (SecurityException e) { // expected } try { r.query(Checkin.Properties.CONTENT_URI, null, null, null, null); fail("SecurityException expected"); } catch (SecurityException e) { // expected } }
From source file:de.aw.awlib.gv.CalendarReminder.java
/** * Erstellt einen Event im ausgewaehlten Caleendar * * @param calendarID//w w w . j a va2 s . co m * ID des ausgewaehlten Kalenders * @param start * Startdatum des Events * @param dauer * Dauer des Events * @param title * Title des Events * @param body * Body des Events (optional) * @return die ID des eingefuegten Events. -1, wenn ein Fehler aufgetreten ist. */ public long createEvent(long calendarID, @NonNull Date start, long dauer, @NonNull String title, @Nullable String body) { long id = -1; if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED) { ContentResolver cr = mContext.getContentResolver(); ContentValues values = createEventValues(calendarID, start, dauer, title, body); Uri uri = cr.insert(Events.CONTENT_URI, values); if (uri != null) { id = Long.parseLong(uri.getLastPathSegment()); } } return id; }