@Override public final String getType(Uri uri) { switch (sURIMatcher.match(uri)) { case SIMPLEENTITY_DIR: return CONTENT_TYPE; case SIMPLEENTITY_ID: return CONTENT_ITEM_TYPE; default : throw new IllegalArgumentException("Unsupported URI: " + uri); } } }
/** Initialize a new matcher object without any matches, then use .addURI(String authority, String path, int match) to add matches */ public static UriMatcher buildUriMatcher() { // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); /* All paths added to the UriMatcher have a corresponding int. For each kind of uri you may want to access, add the corresponding match with addURI. The two calls below add matches for the task directory and a single item by ID. */ uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS); uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID); return uriMatcher; }
private static final UriMatcher uriMatcher; static { uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(PROVIDER_NAME, "sampleuri1", SAMPLE1); uriMatcher.addURI(PROVIDER_NAME, "sampleuri1/#", SAMPLE1_ID); uriMatcher.addURI(PROVIDER_NAME, "sampleuri2", SAMPLE2); uriMatcher.addURI(PROVIDER_NAME, "sampleuri2/#", SAMPLE2_ID); }
private boolean isCollectionUri(Uri url) { return(MATCHER.match(url) == CONSTANTS); } }
/** Initialize a new matcher object without any matches, then use .addURI(String authority, String path, int match) to add matches */ public static UriMatcher buildUriMatcher() { // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); /* All paths added to the UriMatcher have a corresponding int. For each kind of uri you may want to access, add the corresponding match with addURI. The two calls below add matches for the task directory and a single item by ID. */ uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS); uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID); return uriMatcher; }
@Override public boolean onCreate() { String packageName = getContext().getPackageName(); AUTHORITY = packageName + ".provider.email"; CONTENT_URI = Uri.parse("content://" + AUTHORITY); uriMatcher.addURI(AUTHORITY, "account/*/messages", MESSAGES); uriMatcher.addURI(AUTHORITY, "account/*/messages/threaded", MESSAGES_THREADED); uriMatcher.addURI(AUTHORITY, "account/*/thread/#", MESSAGES_THREAD); return true; }
private boolean isCollectionUri(Uri url) { return(MATCHER.match(url) == CONSTANTS); } }
/** Initialize a new matcher object without any matches, then use .addURI(String authority, String path, int match) to add matches */ public static UriMatcher buildUriMatcher() { // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); /* All paths added to the UriMatcher have a corresponding int. For each kind of uri you may want to access, add the corresponding match with addURI. The two calls below add matches for the task directory and a single item by ID. */ uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS); uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID); return uriMatcher; }
@Override public void attachInfo(Context context, ProviderInfo info) { super.attachInfo(context, info); TRANSACTION_URI = Uri.parse("content://" + info.authority + "/transaction"); matcher.addURI(info.authority, "transaction/#", TRANSACTION); matcher.addURI(info.authority, "transaction", TRANSACTIONS); }
@Override public String getType(Uri uri) { switch (uriMatcher.match(uri)) { case BOOK_DIR: return "vnd.android.cursor.dir/vnd.com.example.databasetest. provider.book"; case BOOK_ITEM: return "vnd.android.cursor.item/vnd.com.example.databasetest. provider.book"; case CATEGORY_DIR: return "vnd.android.cursor.dir/vnd.com.example.databasetest. provider.category"; case CATEGORY_ITEM: return "vnd.android.cursor.item/vnd.com.example.databasetest. provider.category"; } return null; }
/** Initialize a new matcher object without any matches, then use .addURI(String authority, String path, int match) to add matches */ public static UriMatcher buildUriMatcher() { // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); /* All paths added to the UriMatcher have a corresponding int. For each kind of uri you may want to access, add the corresponding match with addURI. The two calls below add matches for the task directory and a single item by ID. */ uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS); uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID); return uriMatcher; }
/** * Register a {@link QueryHandler} to handle a certain {@link Uri} for * {@link #query(Uri, String[], String, String[], String)} */ protected void registerQueryHandler(QueryHandler handler) { if (queryHandlers.contains(handler)) { return; } queryHandlers.add(handler); int code = queryHandlers.indexOf(handler); uriMatcher.addURI(AUTHORITY, handler.getPath(), code); }
/** * @param uri localtion of the data * @return correct sqlite table for the given uri */ public String getTable(final Uri uri) { if (uri == null) { return null; } final int match = sURIMatcher.match(uri); switch (match) { case SINGLE_PREFERENCE: case MODULE_PREFERENCE: case ALL_PREFERENCE: default: return TrayDBHelper.TABLE_NAME; case INTERNAL_SINGLE_PREFERENCE: case INTERNAL_MODULE_PREFERENCE: case INTERNAL_ALL_PREFERENCE: return TrayDBHelper.INTERNAL_TABLE_NAME; } }
/** Initialize a new matcher object without any matches, then use .addURI(String authority, String path, int match) to add matches */ public static UriMatcher buildUriMatcher() { // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); /* All paths added to the UriMatcher have a corresponding int. For each kind of uri you may want to access, add the corresponding match with addURI. The two calls below add matches for the task directory and a single item by ID. */ uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS); uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID); return uriMatcher; }
@Override public boolean canHandleRequest(@NonNull Request data) { final Uri uri = data.uri; return uri != null && SCHEME_CONTENT.equals(uri.getScheme()) && ContactsContract.Contacts.CONTENT_URI.getHost().equals(uri.getHost()) && matcher.match(data.uri) != UriMatcher.NO_MATCH; }
/** Initialize a new matcher object without any matches, then use .addURI(String authority, String path, int match) to add matches */ public static UriMatcher buildUriMatcher() { // Initialize a UriMatcher with no matches by passing in NO_MATCH to the constructor UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); /* All paths added to the UriMatcher have a corresponding int. For each kind of uri you may want to access, add the corresponding match with addURI. The two calls below add matches for the task directory and a single item by ID. */ uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS); uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS + "/#", TASK_WITH_ID); return uriMatcher; }
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { switch (URI_MATCHER.match(uri)) { case URI_MATCHER_CODE_TWEETS: return sqLiteOpenHelper .getReadableDatabase() .query( TweetsTable.TABLE, projection, selection, selectionArgs, null, null, sortOrder ); default: return null; } }
static void setAuthority(final String authority) { sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH); sURIMatcher.addURI(authority, TrayContract.Preferences.BASE_PATH, ALL_PREFERENCE); // BASE/module sURIMatcher.addURI(authority, TrayContract.Preferences.BASE_PATH + "/*", MODULE_PREFERENCE); // BASE/module/key sURIMatcher.addURI(authority, TrayContract.Preferences.BASE_PATH + "/*/*", SINGLE_PREFERENCE); sURIMatcher.addURI(authority, TrayContract.InternalPreferences.BASE_PATH, INTERNAL_ALL_PREFERENCE); // INTERNAL_BASE/module sURIMatcher.addURI(authority, TrayContract.InternalPreferences.BASE_PATH + "/*", INTERNAL_MODULE_PREFERENCE); // INTERNAL_BASE/module/key sURIMatcher.addURI(authority, TrayContract.InternalPreferences.BASE_PATH + "/*/*", INTERNAL_SINGLE_PREFERENCE); }
private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver) throws FileNotFoundException { switch (URI_MATCHER.match(uri)) { case ID_CONTACTS_CONTACT: return openContactPhotoInputStream(contentResolver, uri); case ID_CONTACTS_LOOKUP: case ID_LOOKUP_BY_PHONE: // If it was a Lookup uri then resolve it first, then continue loading the contact uri. uri = ContactsContract.Contacts.lookupContact(contentResolver, uri); if (uri == null) { throw new FileNotFoundException("Contact cannot be found"); } return openContactPhotoInputStream(contentResolver, uri); case ID_CONTACTS_THUMBNAIL: case ID_CONTACTS_PHOTO: case UriMatcher.NO_MATCH: default: return contentResolver.openInputStream(uri); } }