use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method insert.
/**
* 获取插件 ContentProvider 后
* 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
*
* 手动调用 插件 ContentProvider # insert(...)
*
* @param uri uri
* @param values values
* @return Uri
*/
@Override
public Uri insert(Uri uri, ContentValues values) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.insert(pluginUri, values);
}
return uri;
}
use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method call.
/**
* 获取插件 ContentProvider 后
* 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
*
* 手动调用 插件 ContentProvider # call(...)
*
* @param method method
* @param arg arg
* @param extras extras
* @return Bundle
*/
@Override
public Bundle call(String method, String arg, Bundle extras) {
Log.d(TAG, "call " + method + " with extras : " + extras);
if (extras == null || extras.getString(KEY_WRAPPER_URI) == null) {
return null;
}
Uri uri = Uri.parse(extras.getString(KEY_WRAPPER_URI));
ContentProvider provider = getContentProvider(uri);
if (provider != null) {
return provider.call(method, arg, extras);
}
return null;
}
use of android.content.ContentProvider in project robolectric by robolectric.
the class ShadowContentProviderOperationBuilderTest method build.
@Test
public void build() throws Exception {
Uri uri = Uri.parse("content://authority/path");
ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri);
builder.withSelection("a=?", new String[] { "a" });
builder.withValue("k1", "v1");
ContentValues cv = new ContentValues();
cv.put("k2", "v2");
builder.withValues(cv);
ContentProviderOperation op = builder.build();
assertThat(op).isNotNull();
assertThat(op.getUri()).isEqualTo(uri);
final ContentRequest request = new ContentRequest();
ContentProvider provider = new ContentProvider() {
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return null;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
request.uri = uri;
request.values = values;
request.selection = selection;
request.selectionArgs = selectionArgs;
return 0;
}
};
op.apply(provider, null, 0);
assertThat(request.uri).isEqualTo(uri);
assertThat(request.selection).isEqualTo("a=?");
assertThat(request.selectionArgs).isEqualTo(new String[] { "a" });
assertThat(request.values.containsKey("k1")).isTrue();
assertThat(request.values.containsKey("k2")).isTrue();
}
use of android.content.ContentProvider in project robolectric by robolectric.
the class ShadowContentResolverTest method applyBatchForRegisteredProvider.
@SuppressWarnings("serial")
@Test
public void applyBatchForRegisteredProvider() throws RemoteException, OperationApplicationException {
final List<String> operations = new ArrayList<>();
ShadowContentResolver.registerProviderInternal("registeredProvider", new ContentProvider() {
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
operations.add("query");
MatrixCursor cursor = new MatrixCursor(new String[] { "a" });
cursor.addRow(new Object[] { "b" });
return cursor;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
operations.add("insert");
return ContentUris.withAppendedId(uri, 1);
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
operations.add("delete");
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
operations.add("update");
return 0;
}
});
final Uri uri = Uri.parse("content://registeredProvider/path");
List<ContentProviderOperation> contentProviderOperations = Arrays.asList(ContentProviderOperation.newInsert(uri).withValue("a", "b").build(), ContentProviderOperation.newUpdate(uri).withValue("a", "b").build(), ContentProviderOperation.newDelete(uri).build(), ContentProviderOperation.newAssertQuery(uri).withValue("a", "b").build());
contentResolver.applyBatch("registeredProvider", new ArrayList<>(contentProviderOperations));
assertThat(operations).containsExactly("insert", "update", "delete", "query");
}
use of android.content.ContentProvider in project robolectric by robolectric.
the class ShadowContentResolverTest method getType_shouldReturnProviderValue.
@Test
public void getType_shouldReturnProviderValue() {
ShadowContentResolver.registerProviderInternal(AUTHORITY, new ContentProvider() {
@Override
public boolean onCreate() {
return false;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return new BaseCursor();
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return -1;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return -1;
}
@Override
public String getType(Uri uri) {
return "mytype";
}
});
final Uri uri = Uri.parse("content://" + AUTHORITY + "/some/path");
assertThat(contentResolver.getType(uri)).isEqualTo("mytype");
}
Aggregations