Java Code Examples for android.content.ContentProviderClient#insert()

The following examples show how to use android.content.ContentProviderClient#insert() . 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: SyncStateContract.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static Uri insert(ContentProviderClient provider, Uri uri,
        Account account, byte[] data) throws RemoteException {
    ContentValues values = new ContentValues();
    values.put(Columns.DATA, data);
    values.put(Columns.ACCOUNT_NAME, account.name);
    values.put(Columns.ACCOUNT_TYPE, account.type);
    return provider.insert(uri, values);
}
 
Example 2
Source File: DatabaseHelper.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
private void notifyLocationUpdated(long id) {
    Message msg = handler.obtainMessage();
    msg.what = MSG_LOCATION_UPDATED;
    msg.obj = (Long) id;
    handler.sendMessage(msg);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    prefs.edit().putLong(SettingsFragment.PREF_LIFELINE_LAST, new Date().getTime()).apply();

    Intent lifeline = new Intent(mContext, BackgroundService.class);
    lifeline.setAction(BackgroundService.ACTION_LIFELINE);
    lifeline.putExtra(BackgroundService.EXTRA_ID, id);
    mContext.startService(lifeline);

    try {
        Uri uri = Uri.parse("content://eu.faircode.lifeline/event");
        ContentProviderClient cclient = mContext.getContentResolver().acquireContentProviderClient(uri);
        if (cclient != null) {
            Location location = getLocation(id);
            Uri row = cclient.insert(uri, getLifelineLocation(id, location.getProvider(), location));
            cclient.release();
            Log.i(TAG, "Updated uri=" + row);
        }
    } catch (Throwable ex) {
        Log.e(TAG, "Lifeline: " + ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}
 
Example 3
Source File: QuantumFluxSyncHelper.java    From QuantumFlux with Apache License 2.0 5 votes vote down vote up
public static <T> T insertAndReturn(ContentProviderClient provider, T dataModelObject) throws RemoteException {
    TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass());
    ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
    Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails)
            .appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build();

    Uri itemUri = provider.insert(insertUri, contentValues);

    return QuantumFlux.findSingleItem(itemUri, tableDetails);
}
 
Example 4
Source File: AbstractContentProviderStub.java    From DroidPlugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues contentValues) {
    String targetAuthority = uri.getQueryParameter(Env.EXTRA_TARGET_AUTHORITY);
    if (!TextUtils.isEmpty(targetAuthority) && !TextUtils.equals(targetAuthority, uri.getAuthority())) {
        ContentProviderClient client = getContentProviderClient(targetAuthority);
        try {
            return client.insert(buildNewUri(uri, targetAuthority), contentValues);
        } catch (RemoteException e) {
            handleExpcetion(e);
        }
    }
    return null;
}
 
Example 5
Source File: CPSyncHelper.java    From CPOrm with MIT License 5 votes vote down vote up
public static <T> T insertAndReturn(Context context, boolean notifyChanges, ContentProviderClient provider, T dataModelObject) throws RemoteException {
    TableDetails tableDetails = CPOrm.findTableDetails(context, dataModelObject.getClass());
    ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
    Uri insertUri = UriMatcherHelper.generateItemUri(context, tableDetails)
            .appendQueryParameter(CPOrmContentProvider.PARAMETER_SYNC, "false")
            .appendQueryParameter(CPOrmContentProvider.PARAMETER_NOTIFY_CHANGES, Boolean.toString(notifyChanges)).build();

    Uri itemUri = provider.insert(insertUri, contentValues);

    return CPOrm.findSingleItem(context, itemUri, tableDetails);
}
 
Example 6
Source File: SyncStateContract.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Assigns the data array as the sync state for the given account.
 * @param provider the {@link ContentProviderClient} that is to be used to communicate
 * with the {@link android.content.ContentProvider} that contains the sync state.
 * @param uri the uri of the sync state
 * @param account the {@link Account} whose sync state should be set
 * @param data the byte[] that contains the sync state
 * @throws RemoteException if there is a failure communicating with the remote
 * {@link android.content.ContentProvider}
 */
public static void set(ContentProviderClient provider, Uri uri,
        Account account, byte[] data) throws RemoteException {
    ContentValues values = new ContentValues();
    values.put(Columns.DATA, data);
    values.put(Columns.ACCOUNT_NAME, account.name);
    values.put(Columns.ACCOUNT_TYPE, account.type);
    provider.insert(uri, values);
}