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:totalcross.android.ConnectionManager4A.java
public static void setDefaultConfiguration(int type, String cfg) { if (cfg == null) cfg = ""; switch (type) { case GPRS: {/*ww w .j a va 2 s .co m*/ int id = -1; ContentResolver contentResolver = Launcher4A.loader.getContentResolver(); Cursor cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" }, "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null); if (cursor == null || cursor.getCount() <= 0) { TelephonyManager tel = (TelephonyManager) Launcher4A.loader .getSystemService(Context.TELEPHONY_SERVICE); String networkOperator = tel.getNetworkOperator(); if (networkOperator != null && networkOperator.length() > 0) { int mcc = Integer.parseInt(networkOperator.substring(0, 3)); int mnc = Integer.parseInt(networkOperator.substring(3)); ContentValues values = new ContentValues(); values.put("apn", "tim.br"); values.put("user", "tim"); values.put("password", "tim"); values.put("mcc", mcc); values.put("mnc", mnc); values.put("numeric", mcc + "" + mnc); contentResolver.insert(CONTENT_URI, values); cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" }, "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null); } } if (cursor == null) return; if (cursor.moveToFirst()) id = cursor.getInt(0); cursor.close(); if (id > -1) { ContentValues values = new ContentValues(); //See /etc/apns-conf.xml. The TelephonyProvider uses this file to provide //content://telephony/carriers/preferapn URI mapping values.put("apn_id", id); contentResolver.update(PREFERRED_APN_URI, values, null, null); cursor = contentResolver.query(PREFERRED_APN_URI, new String[] { "name", "apn" }, "_id=" + id, null, null); if (cursor != null) cursor.close(); } } break; case WIFI: connWIFI = connWIFIPrefix + cfg; break; //default: // throw new IllegalArgumentException("Invalid value for argument 'type'"); } }
From source file:info.staticfree.android.units.UnitUsageDBHelper.java
/** * Increments the usage counter for the given unit. * @param unit name of the unit//from w w w. ja v a 2 s . com * @param db the unit usage database */ public static void logUnitUsed(String unit, ContentResolver cr) { final String[] selectionArgs = { unit }; final Cursor c = cr.query(UsageEntry.CONTENT_URI, INCREMENT_QUERY_PROJECTION, UsageEntry._UNIT + "=?", selectionArgs, null); if (c.getCount() > 0) { c.moveToFirst(); final int useCount = c.getInt(c.getColumnIndex(UsageEntry._USE_COUNT)); final int id = c.getInt(c.getColumnIndex(UsageEntry._ID)); final ContentValues cv = new ContentValues(); cv.put(UsageEntry._USE_COUNT, useCount + 1); cr.update(ContentUris.withAppendedId(UsageEntry.CONTENT_URI, id), cv, null, null); } else { final ContentValues cv = new ContentValues(); cv.put(UsageEntry._UNIT, unit); cv.put(UsageEntry._USE_COUNT, 1); cv.put(UsageEntry._FACTOR_FPRINT, getFingerprint(unit)); cr.insert(UsageEntry.CONTENT_URI, cv); } c.close(); }
From source file:se.rebootit.android.tagbiljetter.DataParser.java
/** * Write a message to the inbox database * @param address From what phone number * @param timestamp Time of arrival/*from w w w . j ava 2s . co m*/ * @param body Body of the message * @param read Is the message read or not? */ public boolean writeSMStoDatabase(String address, long timestamp, String body, int read) { ContentValues values = new ContentValues(); values.put("address", address); values.put("date", timestamp); values.put("read", read); values.put("status", 1); values.put("type", 1); values.put("seen", read); values.put("body", body); ContentResolver contentResolver = Biljetter.getContext().getContentResolver(); contentResolver.insert(Uri.parse("content://sms"), values); // Check if the message was saved correctly Cursor cursor = contentResolver.query(Uri.parse("content://sms/inbox"), new String[] { "_id", "thread_id", "address", "person", "date", "body", "type" }, null, null, null); while (cursor.moveToNext()) { long msgTimestamp = cursor.getLong(cursor.getColumnIndex("date")); String msgAddress = cursor.getString(cursor.getColumnIndex("address")); String msgBody = cursor.getString(cursor.getColumnIndex("body")); // It's in there! :D if (timestamp == msgTimestamp && address.equals(msgAddress) && body.equals(msgBody)) { return true; } // No need to scan the whole inbox. if (timestamp >= msgTimestamp) { break; } } // It was not... return false; }
From source file:de.vanita5.twittnuker.activity.FiltersActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_SELECT_USER: { final Fragment filter = mAdapter.getItem(mViewPager.getCurrentItem()); if (resultCode != RESULT_OK || !(filter instanceof FilteredUsersFragment) || !data.hasExtra(EXTRA_USER)) return; final ParcelableUser user = data.getParcelableExtra(EXTRA_USER); final ContentValues values = makeFilterdUserContentValues(user); final ContentResolver resolver = getContentResolver(); resolver.delete(Filters.Users.CONTENT_URI, Where.equals(Filters.Users.USER_ID, user.id).getSQL(), null); resolver.insert(Filters.Users.CONTENT_URI, values); break;//from w ww. j a v a 2s . c o m } } }
From source file:org.getlantern.firetweet.activity.FiltersActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_SELECT_USER: { final Fragment filter = mAdapter.getItem(mViewPager.getCurrentItem()); if (resultCode != RESULT_OK || !(filter instanceof FilteredUsersFragment) || !data.hasExtra(EXTRA_USER)) return; final ParcelableUser user = data.getParcelableExtra(EXTRA_USER); final ContentValues values = ContentValuesCreator.createFilteredUser(user); final ContentResolver resolver = getContentResolver(); resolver.delete(Filters.Users.CONTENT_URI, Expression.equals(Filters.Users.USER_ID, user.id).getSQL(), null);//from www . ja va 2 s . c o m resolver.insert(Filters.Users.CONTENT_URI, values); break; } } }
From source file:net.naonedbus.manager.impl.FavoriManager.java
public void addFavori(final ContentResolver contentResolver, final Arret item) { final ContentValues values = getContentValues(item); contentResolver.insert(FavoriProvider.CONTENT_URI, values); if (mIsImporting == false) notifyOnAdd(item);/*w ww .j av a 2s . c om*/ }
From source file:net.naonedbus.manager.impl.FavoriManager.java
public void addFavori(final ContentResolver contentResolver, final Favori item) { final ContentValues values = getContentValues(item); contentResolver.insert(FavoriProvider.CONTENT_URI, values); if (mIsImporting == false) notifyOnAdd(item);//from w w w . j a v a 2 s .c o m }
From source file:org.getlantern.firetweet.fragment.support.SearchFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);//from w w w . j a v a 2s . c o m final Bundle args = getArguments(); final FragmentActivity activity = getActivity(); mAdapter = new SupportTabsAdapter(activity, getChildFragmentManager(), null, 1); mAdapter.addTab(StatusesSearchFragment.class, args, getString(R.string.statuses), R.drawable.ic_action_twitter, 0, null); mAdapter.addTab(SearchUsersFragment.class, args, getString(R.string.users), R.drawable.ic_action_user, 1, null); mViewPager.setAdapter(mAdapter); mViewPager.setOffscreenPageLimit(2); mPagerIndicator.setViewPager(mViewPager); mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL); mPagerIndicator.setOnPageChangeListener(this); ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator); ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable()); if (savedInstanceState == null && args != null && args.containsKey(EXTRA_QUERY)) { final String query = args.getString(EXTRA_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); if (activity instanceof LinkHandlerActivity) { final ActionBar ab = activity.getActionBar(); if (ab != null) { ab.setSubtitle(query); } } } updateTabOffset(); }
From source file:org.getlantern.firetweet.loader.support.ParcelableUserLoader.java
@Override public SingleResponse<ParcelableUser> loadInBackground() { final Context context = getContext(); final ContentResolver resolver = context.getContentResolver(); if (!mOmitIntentExtra && mExtras != null) { final ParcelableUser user = mExtras.getParcelable(EXTRA_USER); if (user != null) { final ContentValues values = ParcelableUser.makeCachedUserContentValues(user); resolver.insert(CachedUsers.CONTENT_URI, values); return SingleResponse.getInstance(user); }//from w w w. j a v a 2 s . co m } final Twitter twitter = getTwitterInstance(context, mAccountId, true); if (twitter == null) return SingleResponse.getInstance(); if (mLoadFromCache) { final Expression where; final String[] whereArgs; if (mUserId > 0) { where = Expression.equals(CachedUsers.USER_ID, mUserId); whereArgs = null; } else { where = Expression.equalsArgs(CachedUsers.SCREEN_NAME); whereArgs = new String[] { mScreenName }; } final Cursor cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, where.getSQL(), whereArgs, null); final int count = cur.getCount(); try { if (count > 0) { final CachedIndices indices = new CachedIndices(cur); cur.moveToFirst(); return SingleResponse.getInstance(new ParcelableUser(cur, indices, mAccountId)); } } finally { cur.close(); } } try { final User user = TwitterWrapper.tryShowUser(twitter, mUserId, mScreenName); final ContentValues cachedUserValues = createCachedUser(user); final long userId = user.getId(); resolver.insert(CachedUsers.CONTENT_URI, cachedUserValues); final ParcelableUser result = new ParcelableUser(user, mAccountId); if (isMyAccount(context, userId)) { final ContentValues accountValues = new ContentValues(); accountValues.put(Accounts.NAME, result.name); accountValues.put(Accounts.SCREEN_NAME, result.screen_name); accountValues.put(Accounts.PROFILE_IMAGE_URL, result.profile_image_url); accountValues.put(Accounts.PROFILE_BANNER_URL, result.profile_banner_url); final String accountWhere = Expression.equals(Accounts.ACCOUNT_ID, userId).getSQL(); resolver.update(Accounts.CONTENT_URI, accountValues, accountWhere, null); } return SingleResponse.getInstance(result); } catch (final TwitterException e) { return SingleResponse.getInstance(e); } }
From source file:org.mariotaku.twidere.loader.support.ParcelableUserLoader.java
@Override public SingleResponse<ParcelableUser> loadInBackground() { final Context context = getContext(); final ContentResolver resolver = context.getContentResolver(); if (!mOmitIntentExtra && mExtras != null) { final ParcelableUser user = mExtras.getParcelable(EXTRA_USER); if (user != null) { final ContentValues values = ParcelableUser.makeCachedUserContentValues(user); resolver.insert(CachedUsers.CONTENT_URI, values); return SingleResponse.getInstance(user); }/*ww w.ja v a2s . co m*/ } final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, mAccountId, true); if (twitter == null) return SingleResponse.getInstance(); if (mLoadFromCache) { final Expression where; final String[] whereArgs; if (mUserId > 0) { where = Expression.equals(CachedUsers.USER_ID, mUserId); whereArgs = null; } else { where = Expression.equalsArgs(CachedUsers.SCREEN_NAME); whereArgs = new String[] { mScreenName }; } final Cursor cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, where.getSQL(), whereArgs, null); final int count = cur.getCount(); try { if (count > 0) { final CachedIndices indices = new CachedIndices(cur); cur.moveToFirst(); return SingleResponse.getInstance(new ParcelableUser(cur, indices, mAccountId)); } } finally { cur.close(); } } try { final User user = TwitterWrapper.tryShowUser(twitter, mUserId, mScreenName); final ContentValues cachedUserValues = createCachedUser(user); final long userId = user.getId(); resolver.insert(CachedUsers.CONTENT_URI, cachedUserValues); final ParcelableUser result = new ParcelableUser(user, mAccountId); if (isMyAccount(context, userId)) { final ContentValues accountValues = new ContentValues(); accountValues.put(Accounts.NAME, result.name); accountValues.put(Accounts.SCREEN_NAME, result.screen_name); accountValues.put(Accounts.PROFILE_IMAGE_URL, result.profile_image_url); accountValues.put(Accounts.PROFILE_BANNER_URL, result.profile_banner_url); final String accountWhere = Expression.equals(Accounts.ACCOUNT_ID, userId).getSQL(); resolver.update(Accounts.CONTENT_URI, accountValues, accountWhere, null); } return SingleResponse.getInstance(result); } catch (final TwitterException e) { Log.w(LOGTAG, e); return SingleResponse.getInstance(e); } }