本文整理汇总了Java中android.content.UriMatcher类的典型用法代码示例。如果您正苦于以下问题:Java UriMatcher类的具体用法?Java UriMatcher怎么用?Java UriMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UriMatcher类属于android.content包,在下文中一共展示了UriMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadResourceFromUri
import android.content.UriMatcher; //导入依赖的package包/类
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:
// 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);
}
}
示例2: loadResourceFromUri
import android.content.UriMatcher; //导入依赖的package包/类
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);
}
}
示例3: createFromContentProviderResults
import android.content.UriMatcher; //导入依赖的package包/类
@Nullable
public static DatabaseIdRange createFromContentProviderResults(ContentProviderResult[] results, String path){
UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sUriMatcher.addURI(MessengerContentProvider.AUTHORITY, path, MATCH_CODE);
Integer f = null;
Integer l = null;
for(ContentProviderResult result : results){
if(result.uri != null && !result.uri.toString().isEmpty()){
if(sUriMatcher.match(result.uri) != MATCH_CODE){
continue;
}
int dbid = Integer.parseInt(result.uri.getPathSegments().get(1));
if(f == null || dbid < f){
f = dbid;
}
if(l == null || dbid > l){
l = dbid;
}
}
}
return nonNull(f) && nonNull(l) ? new DatabaseIdRange(f, l) : null;
}
示例4: testUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
/**
* Tests that UriMatcher returns the correct integer value for each of the Uri types that
* our ContentProvider can handle.
*/
@Test
public void testUriMatcher() {
UriMatcher testMatcher = FavoritesProvider.buildUriMatcher();
assertEquals("Error: The movie was matched incorrectly.",
testMatcher.match(TEST_MOVIES_DIR), FavoritesProvider.MOVIES);
assertEquals("Error: The movie was matched incorrectly.",
testMatcher.match(TEST_MOVIE_ID_DIR), FavoritesProvider.MOVIE_ID);
assertEquals("Error: The TV Show was matched incorrectly.",
testMatcher.match(TEST_TV_SHOW_DIR), FavoritesProvider.TV_SHOWS);
assertEquals("Error: The TV Show was matched incorrectly.",
testMatcher.match(TEST_TV_SHOW_ID_DIR), FavoritesProvider.TV_SHOW_ID);
assertEquals("Error: The Person was matched incorrectly.",
testMatcher.match(TEST_PERSON_DIR), FavoritesProvider.PERSONS);
assertEquals("Error: The Person was matched incorrectly.",
testMatcher.match(TEST_PERSON_ID_DIR), FavoritesProvider.PERSON_ID);
}
示例5: buildUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
/**
* 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(ArticleContract.AUTHORITY, ArticleContract.PATH_ARTICLES, ARTICLES);
return uriMatcher;
}
示例6: buildUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
/**
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(AUTHORITY, PATH_TASKS, TASKS);
uriMatcher.addURI(AUTHORITY, PATH_TASKS + "/#", TASK_WITH_ID);
return uriMatcher;
}
示例7: testUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
/**
* This function tests that the UriMatcher returns the correct integer value for
* each of the Uri types that the ContentProvider can handle. Uncomment this when you are
* ready to test your UriMatcher.
*/
@Test
public void testUriMatcher() {
/* Create a URI matcher that the TaskContentProvider uses */
UriMatcher testMatcher = TaskContentProvider.buildUriMatcher();
/* Test that the code returned from our matcher matches the expected TASKS int */
String tasksUriDoesNotMatch = "Error: The TASKS URI was matched incorrectly.";
int actualTasksMatchCode = testMatcher.match(TEST_TASKS);
int expectedTasksMatchCode = TaskContentProvider.TASKS;
assertEquals(tasksUriDoesNotMatch,
actualTasksMatchCode,
expectedTasksMatchCode);
/* Test that the code returned from our matcher matches the expected TASK_WITH_ID */
String taskWithIdDoesNotMatch =
"Error: The TASK_WITH_ID URI was matched incorrectly.";
int actualTaskWithIdCode = testMatcher.match(TEST_TASK_WITH_ID);
int expectedTaskWithIdCode = TaskContentProvider.TASK_WITH_ID;
assertEquals(taskWithIdDoesNotMatch,
actualTaskWithIdCode,
expectedTaskWithIdCode);
}
示例8: buildUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
/**
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;
}
示例9: buildUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
static UriMatcher buildUriMatcher() {
// I know what you're thinking. Why create a UriMatcher when you can use regular
// expressions instead? Because you're not crazy, that's why.
// All paths added to the UriMatcher have a corresponding code to return when a match is
// found. The code passed into the constructor represents the code to return for the root
// URI. It's common to use NO_MATCH as the code for this case.
final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
final String authority = WeatherContract.CONTENT_AUTHORITY;
// For each type of URI you want to add, create a corresponding code.
matcher.addURI(authority, WeatherContract.PATH_WEATHER, WEATHER);
matcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*", WEATHER_WITH_LOCATION);
matcher.addURI(authority, WeatherContract.PATH_WEATHER + "/*/#", WEATHER_WITH_LOCATION_AND_DATE);
matcher.addURI(authority, WeatherContract.PATH_LOCATION, LOCATION);
return matcher;
}
示例10: buildUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
private static UriMatcher buildUriMatcher() {
//The code passed into the constructor represents the code to return for the root URI.
final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
final String authority = GalleryContract.CONTENT_AUTHORITY;
//for the type of URI we want to add, create a corresponding code
//for gallery
matcher.addURI(authority, GalleryContract.PATH_IMAGE, IMAGE);
matcher.addURI(authority, GalleryContract.PATH_IMAGE + "/#", IMAGE_ID);
//for article
matcher.addURI(authority, ArticleContract.PATH_ARTICLE, ARTICLE);
matcher.addURI(authority, ArticleContract.PATH_ARTICLE + "/#", ARTICLE_ID);
return matcher;
}
示例11: buildUriMatcher
import android.content.UriMatcher; //导入依赖的package包/类
/**
* Builds up a UriMatcher for search suggestion and shortcut refresh queries.
*/
private static UriMatcher buildUriMatcher() {
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
// to get definitions...
matcher.addURI(AUTHORITY, "dictionary", SEARCH_WORDS);
matcher.addURI(AUTHORITY, "dictionary/#", GET_WORD);
// to get suggestions...
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
/* The following are unused in this implementation, but if we include
* {@link SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} as a column in our suggestions table, we
* could expect to receive refresh queries when a shortcutted suggestion is displayed in
* Quick Search Box, in which case, the following Uris would be provided and we
* would return a cursor with a single item representing the refreshed suggestion data.
*/
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT);
return matcher;
}
示例12: onCreate
import android.content.UriMatcher; //导入依赖的package包/类
@Override
public boolean onCreate() {
/*if (KillSelfHelper.DEBUG) {
LogUtils.d(KillSelfHelper.TAG, TAG + ".onCreate = " + android.os.Process.myPid());
}*/
if (checkInitAuthority(getContext())) {
mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_ALL, GET_ALL);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_STRING, GET_STRING);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_INT, GET_INT);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_LONG, GET_LONG);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_FLOAT, GET_FLOAT);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_BOOLEAN, GET_BOOLEAN);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_CONTAINS, CONTAINS);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_APPLY, APPLY);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_COMMIT, COMMIT);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_REGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER, REGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_UNREGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER, UNREGISTER_ON_SHARED_PREFERENCE_CHANGE_LISTENER);
mUriMatcher.addURI(AUTHORITY, PATH_WILDCARD + PATH_GET_STRING_SET, GET_STRING_SET);
return true;
} else {
return false;
}
}
示例13: delete
import android.content.UriMatcher; //导入依赖的package包/类
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int code = matcher.match(uri);
int result = 0;
switch (code) {
case UriMatcher.NO_MATCH:
break;
case 1:
// 删除所有
result = db.delete(DBHelper.USERTABLE, null, null);
Log.d("qf", "删除所有数据!");
break;
case 2:
// content://com.lenve.cphost.mycontentprovider/user/10
// 按条件删除,id
result = db.delete(DBHelper.USERTABLE, "_id=?", new String[] { ContentUris.parseId(uri) + "" });
Log.d("qf", "根据删除一条数据");
break;
case 3:
// content://com.lenve.cphost.mycontentprovider/user/zhangsan
// uri.getPathSegments()拿到一个List<String>,里边的值分别是0-->user、1-->zhangsan
result = db.delete(DBHelper.USERTABLE, "USERNAME=?", new String[] { uri.getPathSegments().get(1) });
break;
default:
break;
}
return result;
}
示例14: getModelType
import android.content.UriMatcher; //导入依赖的package包/类
private Class<? extends Model> getModelType(Uri uri) {
final int code = URI_MATCHER.match(uri);
if (code != UriMatcher.NO_MATCH) {
return TYPE_CODES.get(code);
}
return null;
}
示例15: setAuthority
import android.content.UriMatcher; //导入依赖的package包/类
/**
* @see TrayContract#setAuthority(String)
*/
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);
}