- 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/
我正在开发目标 Sdk 17 的应用程序。我当前的设备是 Nexus 7。 我的应用应该没有操作栏,所以我在 Activity 中使用主题Theme.Holo.NoActionBar。 我想在右下角(
当某些应用程序完成安装或更新时,应用程序的启动器图标与安装通知一起放置,如下所示: 如何让我的应用程序的图标在安装完成时也显示出来? 最佳答案 答案是你不知道。您在此处看到的 Google 日历通知来
我正在为 Jellybean、KitKat 和 Lollipop 以及多种不同的设备开发 Android 应用。 在项目开始时,我使用 Jellybean API 库和目标 API“anroid-18
我有一个带有 RelativeLayout 的应用程序,其中包含一个 ProgressBar 和一个 WebView。没有什么复杂的。但是,我遇到了一个非常奇怪的崩溃,我什至没有看到 ANR 对话框。
所以...我阅读了 jellybean 更新说明并看到“Jelly Bean 为付费应用引入了应用加密。” 据我所知,当有人将其 apk 移动到另一台设备时,此服务应该会使应用程序无法使用。 但是非软
我有一个播放 MP3 文件的应用程序,这些文件可以在公共(public) URL 上找到。不幸的是,服务器不支持流媒体,但 Android 使用户体验相当可以接受。 除 JellyBean 外,它适用
源代码在这里:https://github.com/novemberox/NavigationTest此示例的修改版本:http://developer.android.com/training/im
看起来 Google 已经为第三方应用提供了 Google Now 的离线语音识别功能。 the app named Utter 正在使用它. 有没有人看到过如何使用这个离线语音记录来执行简单的语音命
我刚买了一台新的 lenovo A3500 (A7-50) 平板电脑,带有 4.2.2 jellybean 系统。我的电脑在 widows 8 上运行。当我通过 USB 电缆连接我的平板电脑时,com
我有一个 Android 应用程序,它在引用的库中使用 Gson jar。我目前使用的是 2.2.4 版本,我有 2 部手机来测试它。 在 Samsung Galaxy S Advance 2.3.6
我刚刚将我的 Galaxy Tab2 从 ICS 软件更新到 Jelly Bean。我正在开发一个应用程序,我在其中加载一些带有一些 js 文件的 Html,调用一些用 Javascript 文件编写
我想做的是从我的应用程序调用电话并在此通话中打开扬声器。 在 android 4.0 上一切正常,我只是在开始调用 Intent 之前设置了 audiomanager.setSpeakerphoneO
我发现 2.3.4 和 4.2 之间 onNewIntent 调用的行为有所不同。 我有一个 launchMode=singleTask Activity 。根据我对 singleTask 工作原理的
谁能阐明在 JellyBean [Android] 的服务中引入 Isolatedprocess 标签的真正/主要优势是什么?这在框架级别或内核级别是否有利,正如我们所看到的那样,在服务中将 isol
我制作了一个 XML,其中包含一个 TextView,在以下代码中有一个 textAlignement:center:
我们正在使用 phonegap 3.2.2 开发一个 Android 混合应用程序。 在其中一个 html 页面中,我们正在渲染一个“svg”元素,其中包含 svg 中的“path”元素。每个路径元素
这是我正在使用的代码 Intent i = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTU
Jellybean 键盘有一个奇怪的问题。当我的用户升级他们的操作系统时,每当他们尝试使用键盘输入数据时,它就是无法输入。期间。 这很奇怪,因为您确实可以专注于文本区域,但在键盘上打字却没有输出。 有
我正在使用 JQM 开发一个移动网站,但在为 Android 版本 4 及更高版本设置正文时遇到问题。地址和主题工作。 这是代码。 var shareEmail = "mailto:"+thisAdd
当 ICS 出现时,引入了几个新的扩展宽度字节码。其中大部分是用于支持巨型 ID 的说明。以下是其中一些新指令,取 self 的 ics/dalvik/opcode-gen/bytecode.txt:
我是一名优秀的程序员,十分优秀!