@Override boolean oneShot(int packet_id, byte[] payload) { if (size <= 1024 * 1024) { values = new ContentValues(); values.put("packet_id", packet_id); values.put("payload", payload); try { cpr.insert(uri, values); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } else { for (int i = 0; i < size; i += (1024 * 1024)) { values = new ContentValues(); values.put("packet_id", packet_id); System.arraycopy(payload, i, sub_packet, 0, 1024 * 1024); values.put("payload", sub_packet); try { cpr.insert(uri, values); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return true; } }
/** * Insert new Google Drive files in the local database. * * @param driveFiles Collection of Google Drive files to insert. */ private void insertNewDriveFiles(Collection<File> driveFiles) { Uri uri = getNotesUri(mAccount.name); Log.d(TAG, "Inserting new Drive files: " + driveFiles.size()); for (File driveFile : driveFiles) { if (driveFile != null) { ContentValues values = new ContentValues(); values.put(NotePad.Notes.COLUMN_NAME_ACCOUNT, mAccount.name); values.put(NotePad.Notes.COLUMN_NAME_FILE_ID, driveFile.getId()); values.put(NotePad.Notes.COLUMN_NAME_TITLE, driveFile.getTitle()); values.put(NotePad.Notes.COLUMN_NAME_NOTE, getFileContent(driveFile)); values.put(NotePad.Notes.COLUMN_NAME_CREATE_DATE, driveFile.getCreatedDate().getValue()); values.put( NotePad.Notes.COLUMN_NAME_MODIFICATION_DATE, driveFile.getModifiedDate().getValue()); try { mProvider.insert(uri, values); } catch (RemoteException e) { e.printStackTrace(); } } } mContext.getContentResolver().notifyChange(uri, null, false); }
public void save() { try { if (contentUri == null) { contentUri = client.insert(ContributionsContentProvider.BASE_URI, this.toContentValues()); } else { client.update(contentUri, toContentValues(), null, null); } } catch (RemoteException e) { throw new RuntimeException(e); } }
@Override boolean oneShot(int packet_id, long[] payload) { values = new ContentValues(); values.put("packet_id", packet_id); for (int i = 0; i < payload.length; i++) { values.put(index[i], payload[i]); } try { cpr.insert(uri, values); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; }
static void createAccount(Context context) { Log.v(TAG, "createAccount"); Account account = searchMyAccount(context); if (account != null) return; account = new Account(USER, ACCOUNT_TYPE); AccountManager accountManager = AccountManager.get(context); if (accountManager.addAccountExplicitly(account, null, null)) { ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY_URI); ContentValues cv = new ContentValues(); cv.put(ContactsContract.Groups.ACCOUNT_NAME, account.name); cv.put(ContactsContract.Groups.ACCOUNT_TYPE, account.type); cv.put(ContactsContract.Settings.UNGROUPED_VISIBLE, 1); try { client.insert( ContactsContract.Settings.CONTENT_URI .buildUpon() .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .build(), cv); } catch (RemoteException e) { Log.e(TAG, e.getMessage(), e); } Bundle syncParams = new Bundle(4); syncParams.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true); syncParams.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false); syncParams.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false); syncParams.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); ContentResolver.requestSync(account, ContactsContract.AUTHORITY, syncParams); Log.v(TAG, "createAccount finished"); } }
@SuppressLint("InlinedApi") public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info) throws RemoteException { ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY); int color = 0xFFC3EA6E; // fallback: "DAVdroid green" if (info.getColor() != null) { Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?"); Matcher m = p.matcher(info.getColor()); if (m.find()) { int color_rgb = Integer.parseInt(m.group(1), 16); int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF; color = (color_alpha << 24) | color_rgb; } } ContentValues values = new ContentValues(); values.put(Calendars.ACCOUNT_NAME, account.name); values.put(Calendars.ACCOUNT_TYPE, account.type); values.put(Calendars.NAME, info.getPath()); values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle()); values.put(Calendars.CALENDAR_COLOR, color); values.put(Calendars.OWNER_ACCOUNT, account.name); values.put(Calendars.SYNC_EVENTS, 1); values.put(Calendars.VISIBLE, 1); values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT); if (info.isReadOnly()) values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ); else { values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER); values.put(Calendars.CAN_ORGANIZER_RESPOND, 1); values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1); } if (android.os.Build.VERSION.SDK_INT >= 15) { values.put( Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE + "," + Events.AVAILABILITY_TENTATIVE); values.put( Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + "," + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE); } if (info.getTimezone() != null) values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone()); Log.i( TAG, "Inserting calendar: " + values.toString() + " -> " + calendarsURI(account).toString()); client.insert(calendarsURI(account), values); }
private void addQuestionToDb(JSONObject question) throws JSONException, RemoteException { ContentValues values = getQuestionContentValues(question); contentProviderClient.insert(BackendContentProvider.CONTENT_QUESTIONS, values); }