2016-05-08 42 views
0

我爲我的內容提供者構建了uriPatternMatcher。
我的uri就像我使用Logger語句的content://com.example.wordapp/wordlist?flashid=1。 什麼應該是我的模式匹配器?查詢參數建設Uri匹配器

我試圖

public static final String CONTENT_AUTHORITY ="com.example.wordapp"; 
public static final Uri BASE_CONTENT_URI =Uri.parse("content://"+CONTENT_AUTHORITY); 
public static final String PATH_WORD ="wordlist"; 
public static final String FLASHCARD_ID="flashid"; 

matcher.addURI(authority, WordContractClass.PATH_WORD + "?"+ WordContractClass.WordListEntry.FLASHCARD_ID+"=#", WORD_WITH_FLASH_LIST); 

匹配器被示出作爲未找到匹配項輸出。

回答

0

您正在錯誤地添加該模式。從UriMatcher的文檔(http://developer.android.com/reference/android/content/UriMatcher.html),你會發現你的第二個參數應該是路徑,第三個參數應該是你的uri應該匹配的代碼。

我不知道究竟你試圖匹配但你應該是這個樣子:

// assuming pathWord is the path to the list and WORDS_WITH_FLASH_LIST is the code that will be returned on a successful match 
matcher.addURI(authority, pathWord + "/#", WORDS_WITH_FLASH_LIST); 

的「#」意味着有此路徑中的多個條目。你不需要「?」你目前擁有。

+0

我想獲取具有相同flashId的所有條目。如果我將路徑(/)追加到我的uri中,而不是追加查詢(?),那麼您的答案可行。 – Ayush

+0

你不應該在你的uri查詢 - 這是Android的設計。它在這方面沒有任何用處 – ucsunil