Java Code Examples for android.content.ContentProviderClient#update()
The following examples show how to use
android.content.ContentProviderClient#update() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginProviderClient2.java From springreplugin with Apache License 2.0 | 6 votes |
/** * 调用插件里的Provider * * @see android.content.ContentProviderClient#update(Uri, ContentValues, String, String[]) */ public static int update(Context c, Uri uri, ContentValues values, String selection, String[] selectionArgs) { ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, ""); if (client != null) { try { Uri toUri = toCalledUri(c, uri); return client.update(toUri, values, selection, selectionArgs); } catch (RemoteException e) { if (LogDebug.LOG) { Log.d(TAG, e.toString()); } } } if (LogDebug.LOG) { Log.d(TAG, String.format("call update %s", uri.toString())); } return -1; }
Example 2
Source File: QuantumFluxSyncHelper.java From QuantumFlux with Apache License 2.0 | 6 votes |
public static <T> void updateColumns(Context context, ContentProviderClient provider, T dataModelObject, String... columns) throws RemoteException { TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)) .appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build(); for (String contentColumn : tableDetails.getColumnNames()) { boolean includeColumn = false; for (String column : columns) { if (contentColumn.equals(column)) { includeColumn = true; break; } } if (!includeColumn) contentValues.remove(contentColumn); } provider.update(itemUri, contentValues, null, null); }
Example 3
Source File: CPSyncHelper.java From CPOrm with MIT License | 6 votes |
public static <T> void updateColumns(Context context, boolean notifyChanges, ContentProviderClient provider, T dataModelObject, String... columns) throws RemoteException { TableDetails tableDetails = CPOrm.findTableDetails(context, dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUri(context, tableDetails, String.valueOf(columnValue)) .appendQueryParameter(CPOrmContentProvider.PARAMETER_SYNC, "false") .appendQueryParameter(CPOrmContentProvider.PARAMETER_NOTIFY_CHANGES, Boolean.toString(notifyChanges)).build(); for (String contentColumn : tableDetails.getColumnNames()) { boolean includeColumn = false; for (String column : columns) { if (contentColumn.equals(column)) { includeColumn = true; break; } } if (!includeColumn) contentValues.remove(contentColumn); } provider.update(itemUri, contentValues, null, null); }
Example 4
Source File: PluginFastInstallProviderProxy.java From springreplugin with Apache License 2.0 | 5 votes |
/** * 根据PluginInfo的信息来通知UI进程去“安装”插件,包括释放Dex等。 * * @param context Context对象 * @param pi PluginInfo对象 * @return 安装是否成功 */ public static boolean install(Context context, PluginInfo pi) { // 若Dex已经释放,则无需处理,直接返回 if (pi.isDexExtracted()) { if (LogDebug.LOG) { LogDebug.w(TAG, "install: Already loaded, no need to install. pi=" + pi); } return true; } ContentProviderClient cpc = getProvider(context); if (cpc == null) { return false; } try { int r = cpc.update(PluginFastInstallProvider.CONTENT_URI, PluginFastInstallProvider.makeInstallValues(pi), PluginFastInstallProvider.SELECTION_INSTALL, null); if (LogDebug.LOG) { LogDebug.i(TAG, "install: Install. pi=" + pi + "; result=" + r); } return r > 0; } catch (RemoteException e) { e.printStackTrace(); } return false; }
Example 5
Source File: CalendarLoader.java From RememBirthday with GNU General Public License v3.0 | 5 votes |
/** * Updates calendar color */ @SuppressWarnings("deprecation") public static void updateCalendarColor(Context context) { int color = PreferencesManager.getCustomCalendarColor(context); ContentResolver contentResolver = context.getContentResolver(); Uri uri = ContentUris.withAppendedId( CalendarLoader.getBirthdayAdapterUri(context, CalendarContract.Calendars.CONTENT_URI), getCalendar(context)); Log.d(TAG, "Updating calendar color to " + color + " with uri " + uri.toString()); ContentProviderClient client = contentResolver .acquireContentProviderClient(CalendarContract.AUTHORITY); if(client != null) { ContentValues values = new ContentValues(); values.put(CalendarContract.Calendars.CALENDAR_COLOR, color); try { client.update(uri, values, null, null); } catch (RemoteException e) { Log.e(TAG, "Error while updating calendar color!", e); } if (android.os.Build.VERSION.SDK_INT < 24) { client.release(); } else { client.close(); } } }
Example 6
Source File: QuantumFluxSyncHelper.java From QuantumFlux with Apache License 2.0 | 5 votes |
public static <T> void update(Context context, ContentProviderClient provider, T dataModelObject) throws RemoteException { TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)) .appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build(); provider.update(itemUri, contentValues, null, null); }
Example 7
Source File: QuantumFluxSyncHelper.java From QuantumFlux with Apache License 2.0 | 5 votes |
public static <T> void updateColumnsExcluding(Context context, ContentProviderClient provider, T dataModelObject, String... columnsToExclude) throws RemoteException { TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)) .appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build(); for (String columnToExclude : columnsToExclude) { contentValues.remove(columnToExclude); } provider.update(itemUri, contentValues, null, null); }
Example 8
Source File: AbstractContentProviderStub.java From DroidPlugin with GNU Lesser General Public License v3.0 | 5 votes |
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { String targetAuthority = uri.getQueryParameter(Env.EXTRA_TARGET_AUTHORITY); if (!TextUtils.isEmpty(targetAuthority) && !TextUtils.equals(targetAuthority, uri.getAuthority())) { ContentProviderClient client = getContentProviderClient(targetAuthority); try { return client.update(buildNewUri(uri, targetAuthority), values, selection, selectionArgs); } catch (RemoteException e) { handleExpcetion(e); } } return 0; }
Example 9
Source File: CPSyncHelper.java From CPOrm with MIT License | 5 votes |
public static <T> void update(Context context, boolean notifyChanges, ContentProviderClient provider, T dataModelObject) throws RemoteException { TableDetails tableDetails = CPOrm.findTableDetails(context, dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUri(context, tableDetails, String.valueOf(columnValue)) .appendQueryParameter(CPOrmContentProvider.PARAMETER_SYNC, "false") .appendQueryParameter(CPOrmContentProvider.PARAMETER_NOTIFY_CHANGES, Boolean.toString(notifyChanges)).build(); provider.update(itemUri, contentValues, null, null); }
Example 10
Source File: CPSyncHelper.java From CPOrm with MIT License | 5 votes |
public static <T> void updateColumnsExcluding(Context context, boolean notifyChanges, ContentProviderClient provider, T dataModelObject, String... columnsToExclude) throws RemoteException { TableDetails tableDetails = CPOrm.findTableDetails(context, dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUri(context, tableDetails, String.valueOf(columnValue)) .appendQueryParameter(CPOrmContentProvider.PARAMETER_SYNC, "false") .appendQueryParameter(CPOrmContentProvider.PARAMETER_NOTIFY_CHANGES, Boolean.toString(notifyChanges)).build(); for (String columnToExclude : columnsToExclude) { contentValues.remove(columnToExclude); } provider.update(itemUri, contentValues, null, null); }
Example 11
Source File: SyncStateContract.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public static void update(ContentProviderClient provider, Uri uri, byte[] data) throws RemoteException { ContentValues values = new ContentValues(); values.put(Columns.DATA, data); provider.update(uri, values, null, null); }
Example 12
Source File: SyncAdapter.java From attendee-checkin with Apache License 2.0 | 4 votes |
private void syncCheckins(ContentProviderClient provider, String cookie) { Cursor cursor = null; try { cursor = provider.query(Table.ATTENDEE.getBaseUri(), new String[]{ Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, }, Table.Attendee.CHECKIN_MODIFIED, null, null); if (0 == cursor.getCount()) { Log.d(TAG, "No checkin to sync."); return; } int syncCount = 0; while (cursor.moveToNext()) { String attendeeId = cursor.getString( cursor.getColumnIndexOrThrow(Table.Attendee.ID)); String eventId = cursor.getString( cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID)); long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN)); long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie); if (serverCheckin >= 0) { ContentValues values = new ContentValues(); values.put(Table.Attendee.CHECKIN_MODIFIED, false); if (0 == serverCheckin) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, serverCheckin); } provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null); ++syncCount; } } Log.d(TAG, syncCount + " checkin(s) synced."); } catch (RemoteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } }