在实现ContentProvider时定义所有uri的文档中有不同的建议。但我对uri matcher部分感到困惑:例如,我有一个名为items的packageorg.company.example,然后定义

 public static final Uri CONTENT_URI =
  Uri.parse("content://org.company.example.sampleprovider/items");

在静态init中,应该使用哪个权限部分来匹配uri:
 private static final UriMatcher uriMatcher;

  static {
   uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
   uriMatcher.addURI("what goes here?", "items", ITEM);
   uriMatcher.addURI("what goes here?", "items/#", ITEM_ID);
  }

最佳答案

public static final String PROVIDER_NAME = "org.company.example.sampleprovider";
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME);
private static final UriMatcher uriMatcher;
static {
   uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
   uriMatcher.addURI(PROVIDER_NAME, "items", ITEM);
   uriMatcher.addURI(PROVIDER_NAME, "items/#", ITEM_ID);
}

08-15 19:35