我为我的SQLiteDatabase创建了一个ContentProvider,而我正在使用的Uri没有被UriMatcher匹配。在我的ContentProvider中,我有以下全局变量:
private static final String AUTHORITY = "com.MyProject.project.MyContentProvider";
private static final String TABLE_BASEPATH = "MyTable_tbl";
public static final Uri My_URI = Uri.parse("content://" + AUTHORITY + "/" + TABLE_BASEPATH);
public static final int EVERYTHING = 100;
public static final int FILTERED = 110;
然后,我有这个UriMatcher:
private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static {
sURIMatcher.addURI(AUTHORITY, TABLE_BASEPATH, EVERYTHING);
sURIMatcher.addURI(AUTHORITY, TABLE_BASEPATH + "/#", FILTERED);
}
在我的活动中,我有:
MyContentProvider mycontentProvider = new MyContentProvider ();
mycontentProvider .delete(MY_URI, null, null);
在我的SQLiteDatabase中,我有:
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASETABLE + " (" + KEY_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_STITCHNAME
+ " TEXT NOT NULL, " + KEY_USES + " TEXT NOT NULL, "
+ KEY_VIDEOID + " TEXT NOT NULL, " + KEY_INSTR
+ " TEXT NOT NULL, " + KEY_NOTES + " TEXT NOT NULL, "
+ KEY_LEVEL + " TEXT NOT NULL, " + KEY_CHART
+ " TEXT NOT NULL)");
}
其中DATABASETABLE是我的SQLiteDatabase中的全局变量。它被赋予如下值:
private static final String DATABASETABLE = "MyTable_tbl";
在我的ContentProvider的删除方法中,我要做的第一件事就是:
int uriType = sURIMatcher.match(uri);
这就是我在我的清单中,在应用程序标签中的内容:
<provider
android:authorities="com.MyProject.project.MyContentProvider"
android:exported="false"
android:name="com.MyProject.project.MyContentProvider">
</provider>
返回uriType = -1。为什么?我如何构建我的Uri有什么问题?