- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Jellybean 4.2.2 上获取正确的 uriType
时遇到问题。下面给出的代码在其他版本上工作正常。
package com.karacraft.security;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import com.karacraft.data.ItemsContract;
import com.karacraft.data.MasterSahabDatabaseHelper;
import com.karacraft.data.MerchandisesContract;
import com.karacraft.data.OrdersContract;
import com.karacraft.data.StaffContract;
import com.karacraft.data.StatsContract;
import com.karacraft.data.SuitsContract;
import com.karacraft.data.TailorsContract;
import com.karacraft.utils.Constants;
public class MasterSahabProvider extends ContentProvider
{
public static final String AUTHORITY ="com.karacraft.security.mastersahab";
public static final String KEY_URI = "/#";
//database
private MasterSahabDatabaseHelper database;
//Table Names
private static final String ITEMS_TABLE = "/" + ItemsContract.TABLE_ITEMS;
private static final String MERCHANDISES_TABLE = "/" + MerchandisesContract.TABLE_MERCHANDISES;
private static final String ORDERS_TABLE = "/" + OrdersContract.TABLE_ORDERS;
private static final String SUITS_TABLE = "/" + SuitsContract.TABLE_SUITS;
private static final String TAILORS_TABLE = "/" + TailorsContract.TABLE_TAILORS;
private static final String STAFF_TABLE = "/" + StaffContract.TABLE_STAFF;
private static final String STATS_TABLE = "/" + StatsContract.TABLE_STATS;
//Uri for Multiple Tables
public static final Uri CONTENT_URI_ITEMS = Uri.parse("content://" + AUTHORITY + ITEMS_TABLE);
public static final Uri CONTENT_URI_MERCHANDISES = Uri.parse("content://" + AUTHORITY + MERCHANDISES_TABLE);
public static final Uri CONTENT_URI_ORDERS = Uri.parse("content://" + AUTHORITY + ORDERS_TABLE);
public static final Uri CONTENT_URI_SUITS = Uri.parse("content://" + AUTHORITY + SUITS_TABLE);
public static final Uri CONTENT_URI_TAILORS = Uri.parse("content://" + AUTHORITY + TAILORS_TABLE);
public static final Uri CONTENT_URI_STAFF = Uri.parse("content://" + AUTHORITY + STAFF_TABLE);
public static final Uri CONTENT_URI_STATS = Uri.parse("content://" + AUTHORITY + STATS_TABLE);
public static final Uri CONTENT_URI_ORDERS_BY_MERC = Uri.parse("content://" + AUTHORITY + ORDERS_TABLE);
//Return value setup for Uri Matchers
private static final int ITEMS = 10;
private static final int ITEM_ID = 20;
private static final int MERCHANDISES = 30;
private static final int MERCHANDISE_ID = 40;
private static final int ORDERS = 50;
private static final int ORDERS_ID = 60;
private static final int SUITS = 70;
private static final int SUITS_ID = 80;
private static final int TAILORS = 90;
private static final int TAILORS_ID = 100;
private static final int STAFF = 110;
private static final int STAFF_ID = 120;
private static final int STATS = 130;
private static final int STATS_ID = 140;
private static final int ORDERS_BY_MERC = 200;
//Custom Method
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static {
uriMatcher.addURI(AUTHORITY, ITEMS_TABLE,ITEMS);
uriMatcher.addURI(AUTHORITY, ITEMS_TABLE + KEY_URI,ITEM_ID);
uriMatcher.addURI(AUTHORITY, MERCHANDISES_TABLE,MERCHANDISES);
uriMatcher.addURI(AUTHORITY, MERCHANDISES_TABLE + KEY_URI,MERCHANDISE_ID);
uriMatcher.addURI(AUTHORITY, ORDERS_TABLE,ORDERS);
uriMatcher.addURI(AUTHORITY, ORDERS_TABLE + KEY_URI,ORDERS_ID);
uriMatcher.addURI(AUTHORITY, SUITS_TABLE,SUITS);
uriMatcher.addURI(AUTHORITY, SUITS_TABLE + KEY_URI,SUITS_ID);
uriMatcher.addURI(AUTHORITY, TAILORS_TABLE,TAILORS);
uriMatcher.addURI(AUTHORITY, TAILORS_TABLE + KEY_URI,TAILORS_ID);
uriMatcher.addURI(AUTHORITY, STAFF_TABLE , STAFF);
uriMatcher.addURI(AUTHORITY, STAFF_TABLE + KEY_URI, STAFF_ID);
uriMatcher.addURI(AUTHORITY, STATS_TABLE , STATS);
uriMatcher.addURI(AUTHORITY, STATS_TABLE + KEY_URI, STATS_ID);
uriMatcher.addURI(AUTHORITY,ORDERS_TABLE ,ORDERS);
}
public boolean onCreate()
{
//Create Database
database = new MasterSahabDatabaseHelper(getContext());
return false;
}
/**
URI uri The URI of the object(s) to access. This is the only argument that must not be null
String[] projection This String array indicates which columns/attributes of the objects you want to access
String selection With this argument you can determine which records to return
String[] selectionArgs The binding parameters to the previous selection argument
String sortOrder If the result should be ordered you must use this argument to determine the sort order
*/
@Nullable
@Override
public Cursor query(Uri uri
, String[] projection
, String selection
, String[] selectionArgs
, String sortOrder)
{
//Using SQLiteQueryBuilder instead of query() method
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
SQLiteDatabase db = database.getWritableDatabase();
Cursor cursor=null;
int uriType = uriMatcher.match(uri);
Log.d(Constants.APP_TAG,"URIType is : " + uriType);
Log.d(Constants.APP_TAG,"URI is : " + uri.toString());
switch (uriType){
case ITEMS:
//Set the table
builder.setTables(ItemsContract.TABLE_ITEMS);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case ITEM_ID:
//Set the table
builder.setTables(ItemsContract.TABLE_ITEMS);
//adding the ID to original Query
builder.appendWhere(ItemsContract.ITEM_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(), uri);
break;
case MERCHANDISES:
//Set the table
builder.setTables(MerchandisesContract.TABLE_MERCHANDISES);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case MERCHANDISE_ID:
//Set the table
builder.setTables(MerchandisesContract.TABLE_MERCHANDISES);
//adding the ID to original Query
builder.appendWhere(MerchandisesContract.MERCHANDISE_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case ORDERS:
//Set the table
builder.setTables(OrdersContract.TABLE_ORDERS);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case ORDERS_ID:
//Set the table
builder.setTables(OrdersContract.TABLE_ORDERS);
//adding the ID to original Query
builder.appendWhere(OrdersContract.ORDER_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case TAILORS:
//Set the table
builder.setTables(TailorsContract.TABLE_TAILORS);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case TAILORS_ID:
//Set the table
builder.setTables(TailorsContract.TABLE_TAILORS);
//adding the ID to original Query
builder.appendWhere(TailorsContract.TAILOR_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case SUITS:
//Set the table
builder.setTables(SuitsContract.TABLE_SUITS);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case SUITS_ID:
//Set the table
builder.setTables(SuitsContract.TABLE_SUITS);
//adding the ID to original Query
builder.appendWhere(SuitsContract.SUITS_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case STAFF:
//Set the table
builder.setTables(StaffContract.TABLE_STAFF);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case STAFF_ID:
//Set the table
builder.setTables(StaffContract.TABLE_STAFF);
//adding the ID to original Query
builder.appendWhere(StaffContract.STAFF_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case STATS:
//Set the table
builder.setTables(StatsContract.TABLE_STATS);
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case STATS_ID:
//Set the table
builder.setTables(StatsContract.TABLE_STATS);
//adding the ID to original Query
builder.appendWhere(StatsContract.STATS_ID + "=" + uri.getLastPathSegment());
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
break;
case ORDERS_BY_MERC:
//Set the table
//builder.setTables("orders LEFT OUTER JOIN staff ON (orders.staff_id = staff._id)");
builder.setTables("orders LEFT OUTER JOIN staff ON orders.staff_id = staff._id");
//builder.setTables("orders,staff");
//adding the ID to original Query
cursor = builder.query(db,projection,selection,selectionArgs,null,null,sortOrder);
// make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(),uri);
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
return cursor;
}
@Nullable
@Override
public String getType(Uri uri)
{
return null;
}
@Nullable
@Override
public Uri insert(Uri uri
, ContentValues values)
{
int uriType = uriMatcher.match(uri);
SQLiteDatabase db = database.getWritableDatabase();
Log.d(Constants.APP_TAG,"URIType is : " + uriType);
Log.d(Constants.APP_TAG,"URI is : " + uri.toString());
long id = 0;
switch (uriType){
case ITEMS:
id = db.insert(ItemsContract.TABLE_ITEMS, null, values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(ITEMS_TABLE + "/" + id);
case MERCHANDISES:
id = db.insert(MerchandisesContract.TABLE_MERCHANDISES,null,values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(MERCHANDISES_TABLE + "/" + id);
case ORDERS:
id = db.insert(OrdersContract.TABLE_ORDERS,null,values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(ORDERS_TABLE + "/" + id);
case SUITS:
id = db.insert(SuitsContract.TABLE_SUITS,null,values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(SUITS_TABLE + "/" + id);
case STAFF:
id = db.insert(StaffContract.TABLE_STAFF,null, values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(STAFF_TABLE + "/" + id);
case TAILORS:
id = db.insert(TailorsContract.TABLE_TAILORS,null,values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(TAILORS_TABLE + "/" + id);
case STATS:
id = db.insert(StatsContract.TABLE_STATS,null,values);
getContext().getContentResolver().notifyChange(uri,null);
return Uri.parse(STATS_TABLE + "/" + id);
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
}
@Override
public int delete(Uri uri
, String selection
, String[] selectionArgs)
{
int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = database.getWritableDatabase();
int rowsDeleted = 0;
String id ="";
Log.d(Constants.APP_TAG,"URIType is : " + uriType);
Log.d(Constants.APP_TAG,"URI is : " + uri.toString());
switch (uriType) {
case ITEMS:
rowsDeleted = sqlDB.delete(ItemsContract.TABLE_ITEMS, selection, selectionArgs);
break;
case ITEM_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(ItemsContract.TABLE_ITEMS, ItemsContract.ITEM_ID + "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(ItemsContract.TABLE_ITEMS, ItemsContract.ITEM_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
case MERCHANDISES:
rowsDeleted = sqlDB.delete(MerchandisesContract.TABLE_MERCHANDISES, selection, selectionArgs);
break;
case MERCHANDISE_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(MerchandisesContract.TABLE_MERCHANDISES, MerchandisesContract.MERCHANDISE_ID+ "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(MerchandisesContract.TABLE_MERCHANDISES, MerchandisesContract.MERCHANDISE_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
case TAILORS:
rowsDeleted = sqlDB.delete(TailorsContract.TABLE_TAILORS, selection, selectionArgs);
break;
case TAILORS_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(TailorsContract.TABLE_TAILORS, TailorsContract.TAILOR_ID + "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(TailorsContract.TABLE_TAILORS, TailorsContract.TAILOR_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
case STAFF:
rowsDeleted = sqlDB.delete(StaffContract.TABLE_STAFF, selection, selectionArgs);
break;
case STAFF_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(StaffContract.TABLE_STAFF, StaffContract.STAFF_ID + "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(StaffContract.TABLE_STAFF, StaffContract.STAFF_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
case SUITS:
rowsDeleted = sqlDB.delete(SuitsContract.TABLE_SUITS, selection, selectionArgs);
break;
case SUITS_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(SuitsContract.TABLE_SUITS, SuitsContract.SUITS_ID + "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(SuitsContract.TABLE_SUITS, SuitsContract.SUITS_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
case ORDERS:
rowsDeleted = sqlDB.delete(OrdersContract.TABLE_ORDERS, selection, selectionArgs);
break;
case ORDERS_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(OrdersContract.TABLE_ORDERS, OrdersContract.ORDER_ID + "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(OrdersContract.TABLE_ORDERS, OrdersContract.ORDER_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
case STATS:
rowsDeleted = sqlDB.delete(StatsContract.TABLE_STATS, selection, selectionArgs);
break;
case STATS_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsDeleted = sqlDB.delete(StatsContract.TABLE_STATS, StatsContract.STATS_ID + "=" + id, null);
} else {
rowsDeleted = sqlDB.delete(StatsContract.TABLE_STATS, StatsContract.STATS_ID + "=" + id + " AND " + selection, selectionArgs);
}
break;
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return rowsDeleted;
}
@Override
public int update(Uri uri
, ContentValues values
, String selection
, String[] selectionArgs)
{
int uriType = uriMatcher.match(uri);
SQLiteDatabase db = database.getWritableDatabase();
int rowsUpdated=0;
Log.d(Constants.APP_TAG,"URIType is : " + uriType);
Log.d(Constants.APP_TAG,"URI is : " + uri.toString());
switch (uriType){
case ITEMS:
rowsUpdated = db.update(ItemsContract.TABLE_ITEMS,values,selection,selectionArgs);
break;
case ITEM_ID:
String id = uri.getLastPathSegment();
if(TextUtils.isEmpty(selection)){
rowsUpdated = db.update(ItemsContract.TABLE_ITEMS,values, ItemsContract.ITEM_ID + "=" + id,null);
}else{
rowsUpdated = db.update(ItemsContract.TABLE_ITEMS,values, ItemsContract.ITEM_ID + "=" + id + " AND " + selection,selectionArgs);
}
break;
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
getContext().getContentResolver().notifyChange(uri,null);
return rowsUpdated;
}
}
我已经用模拟器和物理设备检查了上面的内容提供程序代码,并且一切正常(我已经在 5.0、5.1 和 6.0 模拟器上试过了)。
这是 (JellyBean 4.2.2) 的 Logcat:
02-20 21:12:27.480 1796-1808/? D/PTI: URIType is : -1
02-20 21:12:27.480 1796-1808/? D/PTI: URI is : content://com.karacraft.security.mastersahab/items
02-20 21:12:27.480 1796-1808/? E/DatabaseUtils: Writing exception to parcel
java.lang.IllegalArgumentException: Unknown URI: content://com.karacraft.security.mastersahab/items
at com.karacraft.security.MasterSahabProvider.query(MasterSahabProvider.java:260)
at android.content.ContentProvider.query(ContentProvider.java:652)
at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:113)
at android.os.Binder.execTransact(Binder.java:351)
at dalvik.system.NativeStart.run(Native Method)
在其他系统上,URI 总是按预期出现。
这是 KitKat 4.4.4 的 Logcat:
02-21 01:06:51.591 1872-1884/? D/PTI: URIType is : 10
02-21 01:06:51.591 1872-1884/? D/PTI: URI is : content://com.karacraft.security.mastersahab/items
02-21 01:06:51.631 1872-1883/? D/PTI: URIType is : 50
02-21 01:06:51.631 1872-1883/? D/PTI: URI is : content://com.karacraft.security.mastersahab/orders
02-21 01:06:51.631 1872-1884/? D/PTI: URIType is : 70
02-21 01:06:51.631 1872-1884/? D/PTI: URI is : content://com.karacraft.security.mastersahab/suits
02-21 01:06:51.631 1872-1883/? D/PTI: URIType is : 90
02-21 01:06:51.631 1872-1883/? D/PTI: URI is : content://com.karacraft.security.mastersahab/tailors
02-21 01:06:51.631 1872-1884/? D/PTI: URIType is : 130
02-21 01:06:51.631 1872-1884/? D/PTI: URI is : content://com.karacraft.security.mastersahab/stats
02-21 01:06:51.641 1872-1883/? D/PTI: URIType is : 110
02-21 01:06:51.641 1872-1883/? D/PTI: URI is : content://com.karacraft.security.mastersahab/staff
02-21 01:06:51.641 1872-1884/? D/PTI: URIType is : 30
02-21 01:06:51.641 1872-1884/? D/PTI: URI is : content://com.karacraft.security.mastersahab/merchandises
它在 Kitkat 上显示正确的 URI。
将表名的前导斜杠更改为 URI 解决了这个问题。
//Table Names
private static final String ITEMS_TABLE = "/" + ItemsContract.TABLE_ITEMS;
private static final String MERCHANDISES_TABLE = "/" + MerchandisesContract.TABLE_MERCHANDISES;
private static final String ORDERS_TABLE = "/" + OrdersContract.TABLE_ORDERS;
private static final String SUITS_TABLE = "/" + SuitsContract.TABLE_SUITS;
private static final String TAILORS_TABLE = "/" + TailorsContract.TABLE_TAILORS;
private static final String STAFF_TABLE = "/" + StaffContract.TABLE_STAFF;
private static final String STATS_TABLE = "/" + StatsContract.TABLE_STATS;
//Uri for Multiple Tables
public static final Uri CONTENT_URI_ITEMS = Uri.parse("content://" + AUTHORITY + ITEMS_TABLE);
public static final Uri CONTENT_URI_MERCHANDISES = Uri.parse("content://" + AUTHORITY + MERCHANDISES_TABLE);
public static final Uri CONTENT_URI_ORDERS = Uri.parse("content://" + AUTHORITY + ORDERS_TABLE);
public static final Uri CONTENT_URI_SUITS = Uri.parse("content://" + AUTHORITY + SUITS_TABLE);
public static final Uri CONTENT_URI_TAILORS = Uri.parse("content://" + AUTHORITY + TAILORS_TABLE);
public static final Uri CONTENT_URI_STAFF = Uri.parse("content://" + AUTHORITY + STAFF_TABLE);
public static final Uri CONTENT_URI_STATS = Uri.parse("content://" + AUTHORITY + STATS_TABLE);
这个
//Table Names
private static final String ITEMS_TABLE = ItemsContract.TABLE_ITEMS;
private static final String MERCHANDISES_TABLE = MerchandisesContract.TABLE_MERCHANDISES;
private static final String ORDERS_TABLE = OrdersContract.TABLE_ORDERS;
private static final String SUITS_TABLE = SuitsContract.TABLE_SUITS;
private static final String TAILORS_TABLE = TailorsContract.TABLE_TAILORS;
private static final String STAFF_TABLE = StaffContract.TABLE_STAFF;
private static final String STATS_TABLE = StatsContract.TABLE_STATS;
//Uri for Multiple Tables
public static final Uri CONTENT_URI_ITEMS = Uri.parse("content://" + AUTHORITY + "/" + ITEMS_TABLE);
public static final Uri CONTENT_URI_MERCHANDISES = Uri.parse("content://" + AUTHORITY + "/" +MERCHANDISES_TABLE);
public static final Uri CONTENT_URI_ORDERS = Uri.parse("content://" + AUTHORITY + "/" +ORDERS_TABLE);
public static final Uri CONTENT_URI_SUITS = Uri.parse("content://" + AUTHORITY + "/" +SUITS_TABLE);
public static final Uri CONTENT_URI_TAILORS = Uri.parse("content://" + AUTHORITY + "/" +TAILORS_TABLE);
public static final Uri CONTENT_URI_STAFF = Uri.parse("content://" + AUTHORITY + "/" +STAFF_TABLE);
public static final Uri CONTENT_URI_STATS = Uri.parse("content://" + AUTHORITY + "/" +STATS_TABLE);
最佳答案
在 Android 4.3 中添加了对带有前导斜杠的路径的支持。参见 addUri 的描述, 说明
Starting from API level JELLY_BEAN_MR2, this method will accept a leading slash in the path.
因此只需删除路径中的前导斜线即可。
即替换
uriMatcher.addURI(AUTHORITY, ITEMS_TABLE,ITEMS);
通过
uriMatcher.addURI(AUTHORITY, ItemsContract.TABLE_ITEMS);
顺便说一句。 query
方法中的最后一个 case
语句缺少一个 break;
这意味着 Uri
将始终抛出异常.
关于安卓 : Content Provider : Uri Type Wrong on Jellybean 4. 2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35529287/
我想将 EditText 始终设置为 LTR,我该怎么做?android:textDirection 似乎确实是答案,我无法让项目使用该指令进行编译 最佳答案 为 editText 使用引力 andr
我希望我的应用在每次打开时都显示登录屏幕。使用 android:clearTaskOnLaunch="true" 一切正常。但是有一个错误,只有在手机关机并且应用程序首先使用小部件启动时才会发生。 I
实际上我的要求是我想将动态文件加载到像图像一样的网页中。视频,音频等,它来自 Assets 或应用程序自己的文件目录,这不是问题。 我尝试使用以下两种方式。 方式一 这是我的 html 文件在 ass
我正在触发一个 DatePickerDialog,在 api 22 (Android 5.1) 之前它一直在工作并显示良好,我在上面设置混合和最大日期(最小 = 当前日期,最大 = 从当前日期开始的
我有一个 ListView ,我在其中将标题 View 添加到该列表。一切都很好,但是当滚动列表 headerview 也随着列表移动时,所以我想避免 headerview 滚动,我的意思是当我列表到
虽然我在android上做过一些app,但我还是一头雾水。是否可以使用 SDK 4.0 中的功能,并在 android 2.1 或更低版本上运行该应用程序? 我尝试了你们提到的方法,但出现错误 - F
您好,我正在开发小型 android 应用程序,我想在其中显示带有一些元素的简单 gridview。它工作正常。唯一的问题是即使有空间,它也总是只显示两列。它平均将屏幕分成 2 列并仅显示两个元素。如
我正在使用 Android 2.3.3 API 构建一个应用程序。我需要识别方向的变化并执行一些操作。所以我在 Android Manifest 中添加了以下内容, android:configCha
我正在尝试在“点击”包含特定 MIME 类型的 nfc 标签时开始一项 Activity 。我制作了一个 mime 类型为“text/plain”的标签,并将其添加到 list 中:
我可以将一些数据保存到文件中 val byteArrayOutputStream = ByteArrayOutputStream() byteArrayOutputStream.wri
我正在尝试解析一个包含复杂阿拉伯字母的 XML 文件.. 当我在 android 2.3.7 上测试时,并不是所有的阿拉伯字母都被支持,仍然有一些复杂的显示为方 block .. 但是在 androi
我需要编写一个方法来确定设备是平板电脑还是手机。我不需要根据这个显示不同的用户界面。我只需要有关设备的信息,以便将来我可以将其发送到指标。 在互联网上,我找到了很多方法来确定设备是否是平板电脑。我已经
我正在玩文字转语音,让我的测试应用程序更有趣。它适用于模拟器,但不适用于我的手机,因为我的默认语言环境不是英语。 但是,文本是英文的,所以 tts 当然应该使用英文。据我所知,我可以实现一个自动安装,
我正在使用 MVVM 和整洁的架构编写应用程序。在其中一个屏幕上,我需要使用 pagination 实现 RecyclerView。我将使用库 Paging3。 Android 开发者推荐在存储库层使
这个问题在这里已经有了答案: I lost my .keystore file? (12 个回答) 4年前关闭。 当我以前的操作系统损坏并安装新的(7 月 3 日)时,以前的 android_key_
我正在使用 MVVM 和整洁的架构编写应用程序。在其中一个屏幕上,我需要使用 pagination 实现 RecyclerView。我将使用库 Paging3。 Android 开发者推荐在存储库层使
在我的 v27\style.xml 中,我有以下代码来设置白色导航栏: @color/colorPrimary @color/colorPrimaryDark @color/
我想通过发送电子邮件 startActivity(Intent.createChooser(new Intent(android.content.Intent.ACTION_SEND))) 我知道要将
我实现了一个自定义 ListView ,它看起来像 Twitter 时间线。 adapter = new MyClickableListAdapter(this, R.layout.timeline,
我有一个显示启动画面的自定义对话框; mSplashDialog = new Dialog(MyActivity.this,R.layout.splash); mSplashDialog.setCon
我是一名优秀的程序员,十分优秀!