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.akop.bach.parser.XboxLiveParser.java
public void createAccount(BasicAccount account, ContentValues cv) { XboxLiveAccount xblAccount = (XboxLiveAccount) account; // Save changes to preferences xblAccount.setGamertag(cv.getAsString(Profiles.GAMERTAG)); xblAccount.setLastSummaryUpdate(System.currentTimeMillis()); xblAccount.setIconUrl(cv.getAsString(Profiles.ICON_URL)); xblAccount.setGoldStatus(cv.getAsBoolean(Profiles.IS_GOLD)); account.save(Preferences.get(mContext)); // Add profile to database ContentResolver cr = mContext.getContentResolver(); cr.insert(Profiles.CONTENT_URI, cv); cr.notifyChange(Profiles.CONTENT_URI, null); }
From source file:org.servalproject.maps.bridge.AutoUploadReceiver.java
private void doUpload(Context context, Intent intent, String uploadUrl) { // get the URI of the new POI Uri mNewPoiUri = (Uri) intent.getParcelableExtra("uri"); if (mNewPoiUri == null) { Log.w(sTag, "missing uri data in intent"); return;//from w w w.ja v a 2 s . co m } // get the poi data ContentResolver mContentResolver = context.getContentResolver(); Cursor mCursor = mContentResolver.query(mNewPoiUri, null, null, null, null); // check on what was returned if (mCursor == null) { Log.w(sTag, "unable to lookup new POI details"); return; } if (mCursor.getCount() == 0) { Log.w(sTag, "unable to lookup new POI details"); return; } if (!mCursor.moveToFirst()) { Log.w(sTag, "unable to lookup new POI details"); return; } /* * TODO refactor this code to make it more portable * including the same code in the BatchUploadTask class */ ContentValues mContentValues = new ContentValues(); DatabaseUtils.cursorRowToContentValues(mCursor, mContentValues); String mJsonData = null; // convert the data to JSON try { mJsonData = BasicJsonMaker.makePoiJson(mContentValues); } catch (JSONException e) { Log.e(sTag, "unable to encode JSON data for '" + mCursor.getString(mCursor.getColumnIndex(PointsOfInterestContract.Table._ID)), e); mJsonData = null; } // build the log entry mContentValues = new ContentValues(); mContentValues.put(LogContract.Table.POI_ID, mCursor.getString(mCursor.getColumnIndex(PointsOfInterestContract.Table._ID))); mContentValues.put(LogContract.Table.POI_TITLE, mCursor.getString(mCursor.getColumnIndex(PointsOfInterestContract.Table.TITLE))); mContentValues.put(LogContract.Table.JSON_CONTENT, mJsonData); // add the appropriate upload flag if (mJsonData == null) { mContentValues.put(LogContract.Table.UPLOAD_STATUS, LogContract.INVALID_JSON_FLAG); } else { mContentValues.put(LogContract.Table.UPLOAD_STATUS, LogContract.UPLOAD_PENDING_FLAG); } mContentValues.put(LogContract.Table.TIMESTAMP, System.currentTimeMillis()); // add the table row Uri mNewLogRecord = mContentResolver.insert(LogContract.CONTENT_URI, mContentValues); /* * upload the new record */ ContentValues mUpdateValues; String[] mProjection = new String[2]; mProjection[0] = LogContract.Table._ID; mProjection[1] = LogContract.Table.JSON_CONTENT; mCursor = mContentResolver.query(mNewLogRecord, mProjection, null, null, null); if (mCursor == null || mCursor.getCount() == 0 || mCursor.moveToFirst() == false) { Log.w(sTag, "unable to lookup new log entry"); return; } boolean mUploadStatus = BasicHttpUploader.doBasicPost(uploadUrl, mCursor.getString(mCursor.getColumnIndex(mProjection[1]))); // define selection criteria for the update String mSelection = LogContract.Table._ID + " = ?"; String[] mSelectionArgs = new String[1]; mSelectionArgs[0] = mCursor.getString(mCursor.getColumnIndex(LogContract.Table._ID)); if (mUploadStatus) { // the upload was a success mUpdateValues = new ContentValues(); mUpdateValues.put(LogContract.Table.UPLOAD_STATUS, LogContract.UPLOAD_SUCCESS_FLAG); mUpdateValues.put(LogContract.Table.TIMESTAMP, System.currentTimeMillis()); } else { // the upload was a failure mUpdateValues = new ContentValues(); mUpdateValues.put(LogContract.Table.UPLOAD_STATUS, LogContract.UPLOAD_FAILED_FLAG); mUpdateValues.put(LogContract.Table.TIMESTAMP, System.currentTimeMillis()); } // update the log entry mContentResolver.update(LogContract.CONTENT_URI, mUpdateValues, mSelection, mSelectionArgs); }
From source file:com.akop.bach.parser.XboxLiveParser.java
private void parseSendMessage(XboxLiveAccount account, String[] recipients, String body) throws IOException, ParserException { if (!account.isGold()) throw new ParserException(mContext, R.string.account_cant_send); long started = System.currentTimeMillis(); String token = getVToken(String.format(URL_VTOKEN_MESSAGES, mLocale)); String url = String.format(URL_JSON_SEND_MESSAGE, mLocale); List<NameValuePair> inputs = new ArrayList<NameValuePair>(100); // Add recipients for (String recipient : recipients) addValue(inputs, "recipients", recipient); // Add message addValue(inputs, "message", body); // Req. ver. token addValue(inputs, "__RequestVerificationToken", token); String page = getResponse(url, inputs, true); if (App.getConfig().logToConsole()) started = displayTimeTaken("Send message page fetch", started); JSONObject json = getJSONObject(page, false); try {/*ww w. j a v a 2 s . c om*/ if (!json.getBoolean("Success")) { if (App.getConfig().logToConsole()) App.logv("XboxLiveParser/parseSendMessage: Parser error: " + page); throw new ParserException( json.optString("Status", mContext.getString(R.string.message_could_not_be_sent))); } String preview = ""; if (body != null) { preview = body.replaceAll("\\W", " "); if (preview.length() > 20) preview = preview.substring(0, 19); } ContentValues cv = new ContentValues(10); cv.put(SentMessages.ACCOUNT_ID, account.getId()); cv.put(SentMessages.RECIPIENTS, joinString(recipients, ",")); cv.put(SentMessages.SENT, System.currentTimeMillis()); cv.put(SentMessages.PREVIEW, preview); cv.put(SentMessages.BODY, body); try { ContentResolver cr = mContext.getContentResolver(); cr.insert(SentMessages.CONTENT_URI, cv); } catch (Exception e) { if (App.getConfig().logToConsole()) e.printStackTrace(); } } catch (JSONException e) { if (App.getConfig().logToConsole()) { App.logv("XboxLiveParser/parseSendMessage: JSON error: " + page); e.printStackTrace(); } } if (App.getConfig().logToConsole()) displayTimeTaken("Message send processing", started); }
From source file:org.mariotaku.twidere.fragment.UserFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { final Context context = getContext(); final AsyncTwitterWrapper twitter = mTwitterWrapper; final ParcelableUser user = getUser(); final UserRelationship userRelationship = mRelationship; if (user == null || twitter == null) return false; switch (item.getItemId()) { case R.id.block: { if (userRelationship == null) return true; if (userRelationship.blocking) { twitter.destroyBlockAsync(user.account_key, user.key); } else {/*from ww w . j av a2 s. co m*/ CreateUserBlockDialogFragment.show(getFragmentManager(), user); } break; } case R.id.report_spam: { ReportSpamDialogFragment.show(getFragmentManager(), user); break; } case R.id.add_to_filter: { if (userRelationship == null) return true; final ContentResolver cr = getContentResolver(); if (userRelationship.filtering) { final String where = Expression.equalsArgs(Filters.Users.USER_KEY).getSQL(); final String[] whereArgs = { user.key.toString() }; cr.delete(Filters.Users.CONTENT_URI, where, whereArgs); Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false); } else { cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user)); Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false); } getFriendship(); break; } case R.id.mute_user: { if (userRelationship == null) return true; if (userRelationship.muting) { twitter.destroyMuteAsync(user.account_key, user.key); } else { CreateUserMuteDialogFragment.show(getFragmentManager(), user); } break; } case R.id.mention: { final Intent intent = new Intent(INTENT_ACTION_MENTION); final Bundle bundle = new Bundle(); bundle.putParcelable(EXTRA_USER, user); intent.putExtras(bundle); startActivity(intent); break; } case R.id.send_direct_message: { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_TWIDERE); builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION); builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, user.account_key.toString()); builder.appendQueryParameter(QUERY_PARAM_USER_KEY, user.key.toString()); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentialsUtils.getCredentials(getActivity(), user.account_key)); intent.putExtra(EXTRA_USER, user); startActivity(intent); break; } case R.id.set_color: { final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class); intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.key)); intent.putExtra(EXTRA_ALPHA_SLIDER, false); intent.putExtra(EXTRA_CLEAR_BUTTON, true); startActivityForResult(intent, REQUEST_SET_COLOR); break; } case R.id.clear_nickname: { mUserColorNameManager.clearUserNickname(user.key); break; } case R.id.set_nickname: { final String nick = mUserColorNameManager.getUserNickname(user.key); SetUserNicknameDialogFragment.show(getFragmentManager(), user.key, nick); break; } case R.id.add_to_list: { final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST); intent.setClass(getActivity(), UserListSelectorActivity.class); intent.putExtra(EXTRA_ACCOUNT_KEY, user.account_key); intent.putExtra(EXTRA_SCREEN_NAME, DataStoreUtils.getAccountScreenName(getActivity(), user.account_key)); startActivityForResult(intent, REQUEST_ADD_TO_LIST); break; } case R.id.open_with_account: { final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT); intent.setClass(getActivity(), AccountSelectorActivity.class); intent.putExtra(EXTRA_SINGLE_SELECTION, true); intent.putExtra(EXTRA_ACCOUNT_HOST, user.key.getHost()); startActivityForResult(intent, REQUEST_SELECT_ACCOUNT); break; } case R.id.follow: { if (userRelationship == null) return true; final boolean updatingRelationship = twitter.isUpdatingRelationship(user.account_key, user.key); if (!updatingRelationship) { if (userRelationship.following) { DestroyFriendshipDialogFragment.show(getFragmentManager(), user); } else { twitter.createFriendshipAsync(user.account_key, user.key); } } return true; } case R.id.enable_retweets: { final boolean newState = !item.isChecked(); final FriendshipUpdate update = new FriendshipUpdate(); update.retweets(newState); twitter.updateFriendship(user.account_key, user.key.getId(), update); item.setChecked(newState); return true; } case R.id.muted_users: { IntentUtils.openMutesUsers(getActivity(), user.account_key); return true; } case R.id.blocked_users: { IntentUtils.openUserBlocks(getActivity(), user.account_key); return true; } case R.id.incoming_friendships: { IntentUtils.openIncomingFriendships(getActivity(), user.account_key); return true; } case R.id.user_mentions: { IntentUtils.openUserMentions(context, user.account_key, user.screen_name); return true; } case R.id.saved_searches: { IntentUtils.openSavedSearches(context, user.account_key); return true; } case R.id.scheduled_statuses: { IntentUtils.openScheduledStatuses(context, user.account_key); return true; } case R.id.open_in_browser: { final Uri uri = LinkCreator.getUserWebLink(user); final Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setPackage(IntentUtils.getDefaultBrowserPackage(context, uri, true)); if (intent.resolveActivity(context.getPackageManager()) != null) { startActivity(intent); } return true; } default: { final Intent intent = item.getIntent(); if (intent != null && intent.resolveActivity(context.getPackageManager()) != null) { startActivity(intent); } break; } } return true; }
From source file:org.mariotaku.twidere.util.Utils.java
public static ParcelableStatus findStatus(final Context context, final long account_id, final long status_id) throws TwitterException { if (context == null || account_id <= 0 || status_id <= 0) return null; final ParcelableStatus p_status = findStatusInDatabases(context, account_id, status_id); if (p_status != null) return p_status; final Twitter twitter = getTwitterInstance(context, account_id, true); if (twitter == null) return null; final Status status = twitter.showStatus(status_id); if (status == null || status.getId() <= 0) return null; final String where = Statuses.ACCOUNT_ID + " = " + account_id + " AND " + Statuses.STATUS_ID + " = " + status.getId();/* ww w . j a v a 2 s . com*/ final ContentResolver resolver = context.getContentResolver(); final boolean large_profile_image = context.getResources().getBoolean(R.bool.hires_profile_image); resolver.delete(CachedStatuses.CONTENT_URI, where, null); resolver.insert(CachedStatuses.CONTENT_URI, makeStatusContentValues(status, account_id, large_profile_image)); return new ParcelableStatus(status, account_id, false, large_profile_image, true); }
From source file:co.nerdart.ourss.fragment.FeedsListFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { setFeedSortEnabled(false);//from w w w . ja v a 2s . com switch (item.getItemId()) { case R.id.menu_add_feed: { startActivity(new Intent(Intent.ACTION_INSERT).setData(FeedColumns.CONTENT_URI)); return true; } case R.id.menu_refresh: { if (!FetcherService.isRefreshingFeeds) { getActivity().startService( new Intent(getActivity(), FetcherService.class).setAction(Constants.ACTION_REFRESH_FEEDS)); } return true; } case R.id.menu_settings: { startActivity(new Intent(getActivity(), GeneralPrefsActivity.class)); return true; } case R.id.menu_all_read: { new Thread() { @Override public void run() { ContentResolver cr = getActivity().getContentResolver(); if (cr.update(EntryColumns.CONTENT_URI, FeedData.getReadContentValues(), EntryColumns.WHERE_UNREAD, null) > 0) { cr.notifyChange(FeedColumns.CONTENT_URI, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); cr.notifyChange(EntryColumns.FAVORITES_CONTENT_URI, null); } } }.start(); return true; } case R.id.menu_add_group: { final EditText input = new EditText(getActivity()); input.setSingleLine(true); new AlertDialog.Builder(getActivity()) // .setTitle(R.string.add_group_title) // .setView(input) // // .setMessage(R.string.add_group_sentence) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new Thread() { @Override public void run() { String groupName = input.getText().toString(); if (!groupName.isEmpty()) { ContentResolver cr = getActivity().getContentResolver(); ContentValues values = new ContentValues(); values.put(FeedColumns.IS_GROUP, true); values.put(FeedColumns.NAME, groupName); cr.insert(FeedColumns.GROUPS_CONTENT_URI, values); } } }.start(); } }).setNegativeButton(android.R.string.cancel, null).show(); return true; } case R.id.menu_import: { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.select_file); try { final String[] fileNames = Environment.getExternalStorageDirectory().list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return new File(dir, filename).isFile(); } }); builder.setItems(fileNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { new Thread(new Runnable() { // To not block the UI @Override public void run() { try { OPML.importFromFile(Environment.getExternalStorageDirectory().toString() + File.separator + fileNames[which]); } catch (Exception e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Crouton.makeText(getActivity(), R.string.error_feed_import, Style.INFO); } }); } } }).start(); } }); builder.show(); } catch (Exception e) { Crouton.makeText(getActivity(), R.string.error_feed_import, Style.INFO); } } else { Crouton.makeText(getActivity(), R.string.error_external_storage_not_available, Style.INFO); } return true; } case R.id.menu_export: { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { new Thread(new Runnable() { // To not block the UI @Override public void run() { try { final String filename = Environment.getExternalStorageDirectory().toString() + "/OURSS_" + System.currentTimeMillis() + ".opml"; OPML.exportToFile(filename); getActivity().runOnUiThread(new Runnable() { @Override public void run() { //Toast.makeText(getActivity(), // String.format // (getString(R.string.message_exported_to), // filename),Toast.LENGTH_LONG).show(); Crouton.makeText(getActivity(), String.format(getString(R.string.message_exported_to), filename), Style.INFO); } }); } catch (Exception e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { //Toast.makeText(getActivity(), // R.string.error_feed_export, // Toast.LENGTH_LONG).show(); Crouton.makeText(getActivity(), R.string.error_feed_export, Style.INFO); } }); } } }).start(); } else { //Toast.makeText(getActivity(), R.string.error_external_storage_not_available, // Toast.LENGTH_LONG).show(); Crouton.makeText(getActivity(), R.string.error_external_storage_not_available, Style.INFO); } break; } case R.id.menu_enable_feed_sort: { setFeedSortEnabled(true); return true; } case R.id.menu_disable_feed_sort: { // do nothing as the feed sort gets disabled anyway return true; } } return super.onOptionsItemSelected(item); }
From source file:com.layer8apps.CalendarHandler.java
/************ * PURPOSE: Adds the parsed out events to the calendar * ARGUMENTS: NULL//from www.ja v a 2s. c o m * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com> *************/ private int addDays() { ArrayList<Shift> shifts = buildShifts(); try { // deleteOldEvents(); Preferences pf = new Preferences(this); // Get our stored notification time int notification = pf.getNotification(); // Convert the stored time into minutes switch (notification) { case 0: { notification = 0; break; } case 1: { notification = 5; break; } case 2: { notification = 15; break; } case 3: { notification = 30; break; } case 4: { notification = 60; break; } case 5: { notification = 120; break; } case 6: { notification = 180; break; } } shifts = checkForDuplicates(shifts); if (shifts.size() == 0) { return 0; } TimeZone zone = TimeZone.getDefault(); for (Shift shift : shifts) { /************ * ContentResolver and ContentValues are what we use to add * our calendar events to the device *************/ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); /************ * Here we create our calendar event based on the version code *************/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { cv.put(CalendarContract.Events.CALENDAR_ID, calID); cv.put(CalendarContract.Events.DESCRIPTION, shift.getDepartment()); cv.put(CalendarContract.Events.DTEND, shift.getEndDate().getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, shift.getStartDate().getTimeInMillis()); cv.put(CalendarContract.Events.EVENT_LOCATION, shift.getAddress()); cv.put(CalendarContract.Events.EVENT_TIMEZONE, zone.getID()); cv.put(CalendarContract.Events.HAS_ALARM, (notification == 0) ? 0 : 1); cv.put(CalendarContract.Events.TITLE, shift.getTitle()); } else { cv.put("calendar_id", calID); cv.put("description", shift.getDepartment()); cv.put("dtend", shift.getEndDate().getTimeInMillis()); cv.put("dtstart", shift.getStartDate().getTimeInMillis()); cv.put("eventLocation", shift.getAddress()); cv.put("eventTimezone", zone.getID()); cv.put("title", shift.getTitle()); cv.put("hasAlarm", (notification <= 0) ? 0 : 1); } /************ * Add our events to the calendar based on the Uri we get *************/ Uri uri = cr.insert(getEventsUri(), cv); if (uri == null) { continue; } // Get the ID of the calendar event long eventID = Long.parseLong(uri.getLastPathSegment()); pf.saveShift(String.valueOf(eventID)); /************ * If we retrieved a Uri for the event, try to add the reminder *************/ if (notification > 0) { /************ * Build our reminder based on version code *************/ ContentValues reminders = new ContentValues(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { reminders.put(CalendarContract.Reminders.EVENT_ID, eventID); reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); reminders.put(CalendarContract.Reminders.MINUTES, notification); } else { reminders.put("event_id", eventID); reminders.put("method", 1); reminders.put("minutes", notification); } // Add the reminder to the system cr.insert(getRemindersUri(), reminders); } } } catch (Exception e) { showError( "Could not create calendar events on calendar, please make sure you have a calendar application on your device"); return -1; } return shifts.size(); }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
/************ * PURPOSE: Adds the parsed out events to the calendar * ARGUMENTS: NULL//from www .ja v a2 s .com * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com> *************/ private int addDays() { ArrayList<Shift> shifts = buildShifts(); try { // deleteOldEvents(); Preferences pf = new Preferences(this); // Get our stored notification time int notification = pf.getNotification(); // Convert the stored time into minutes switch (notification) { case 0: { notification = 0; break; } case 1: { notification = 5; break; } case 2: { notification = 15; break; } case 3: { notification = 30; break; } case 4: { notification = 60; break; } case 5: { notification = 120; break; } case 6: { notification = 180; break; } } createJSONArray(shifts); shifts = checkForDuplicates(shifts); if (shifts.size() == 0) { return 0; } TimeZone zone = TimeZone.getDefault(); for (Shift shift : shifts) { /************ * ContentResolver and ContentValues are what we use to add * our calendar events to the device *************/ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); /************ * Here we create our calendar event based on the version code *************/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { cv.put(CalendarContract.Events.CALENDAR_ID, calID); cv.put(CalendarContract.Events.DESCRIPTION, shift.getDepartment()); cv.put(CalendarContract.Events.DTEND, shift.getEndDate().getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, shift.getStartDate().getTimeInMillis()); cv.put(CalendarContract.Events.EVENT_LOCATION, shift.getAddress()); cv.put(CalendarContract.Events.EVENT_TIMEZONE, zone.getID()); cv.put(CalendarContract.Events.HAS_ALARM, (notification == 0) ? 0 : 1); cv.put(CalendarContract.Events.TITLE, shift.getTitle()); } else { cv.put("calendar_id", calID); cv.put("description", shift.getDepartment()); cv.put("dtend", shift.getEndDate().getTimeInMillis()); cv.put("dtstart", shift.getStartDate().getTimeInMillis()); cv.put("eventLocation", shift.getAddress()); cv.put("eventTimezone", zone.getID()); cv.put("title", shift.getTitle()); cv.put("hasAlarm", (notification <= 0) ? 0 : 1); } /************ * Add our events to the calendar based on the Uri we get *************/ Uri uri = cr.insert(getEventsUri(), cv); if (uri == null) { continue; } // Get the ID of the calendar event long eventID = Long.parseLong(uri.getLastPathSegment()); pf.saveShift(String.valueOf(eventID)); /************ * If we retrieved a Uri for the event, try to add the reminder *************/ if (notification > 0) { /************ * Build our reminder based on version code *************/ ContentValues reminders = new ContentValues(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { reminders.put(CalendarContract.Reminders.EVENT_ID, eventID); reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); reminders.put(CalendarContract.Reminders.MINUTES, notification); } else { reminders.put("event_id", eventID); reminders.put("method", 1); reminders.put("minutes", notification); } // Add the reminder to the system cr.insert(getRemindersUri(), reminders); } } } catch (Exception e) { showError( "Could not create calendar events on calendar, please make sure you have a calendar application on your device"); return -1; } return shifts.size(); }
From source file:com.akop.bach.parser.XboxLiveParser.java
private void parseAccountSummary(XboxLiveAccount account) throws ParserException, IOException { ContentValues cv = parseSummaryData(account); ContentResolver cr = mContext.getContentResolver(); long accountId = account.getId(); boolean newRecord = true; long started = System.currentTimeMillis(); Cursor c = cr.query(Profiles.CONTENT_URI, new String[] { Profiles._ID }, Profiles.ACCOUNT_ID + "=" + accountId, null, null); if (c != null) { if (c.moveToFirst()) newRecord = false;// ww w . j av a2s.co m c.close(); } if (newRecord) { cv.put(Profiles.ACCOUNT_ID, account.getId()); cv.put(Profiles.UUID, account.getUuid()); cr.insert(Profiles.CONTENT_URI, cv); } else { cr.update(Profiles.CONTENT_URI, cv, Profiles.ACCOUNT_ID + "=" + accountId, null); } cr.notifyChange(Profiles.CONTENT_URI, null); if (App.getConfig().logToConsole()) displayTimeTaken("Summary update", started); account.refresh(Preferences.get(mContext)); account.setGamertag(cv.getAsString(Profiles.GAMERTAG)); account.setIconUrl(cv.getAsString(Profiles.ICON_URL)); account.setGoldStatus(cv.getAsBoolean(Profiles.IS_GOLD)); account.setLastSummaryUpdate(System.currentTimeMillis()); account.save(Preferences.get(mContext)); }