找不到内容提供商信息

时间:2013-10-16 06:05:47

标签: android xml android-contentprovider

每次我点击按钮将数据添加到我的内容提供商时,我一直收到LogCat错误“无法找到提供商信息”

根据过去关于相同问题的帖子,我检查并确保提供商位于Manifest XML的应用程序部分内,并确保授权机构一直处于写入状态。但我似乎仍然得到同样的错误。

表现XML:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ag.access"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="ag.access.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="ag.access.Farming"
        android:label="@string/title_activity_farming"
        android:parentActivityName="ag.access.MainActivity" >
        <intent-filter>
            <action android:name="ag.access.Farming" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.MainActivity" />
    </activity>
    <activity
        android:name="ag.access.Dairy"
        android:label="@string/title_activity_dairy"
        android:parentActivityName="ag.access.MainActivity" >
        <intent-filter>
            <action android:name="ag.access.Dairy" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.MainActivity" />
    </activity>
    <activity
        android:name="ag.access.Daily_log"
        android:label="@string/title_activity_daily_log"
        android:parentActivityName="ag.access.Dairy" >
        <intent-filter>
            <action android:name="ag.access.Daily_log" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Dairy" />
    </activity>
    <activity
        android:name="ag.access.Viewlogs"
        android:label="@string/title_activity_viewlogs"
        android:parentActivityName="ag.access.Daily_log" >
        <intent-filter>
            <action android:name="ag.access.Viewlogs" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Daily_log" />
    </activity>
    <activity
        android:name="ag.access.Add_Edit_Cows"
        android:label="@string/title_activity_add__edit__cows"
        android:parentActivityName="ag.access.Dairy" >
        <intent-filter>
            <action android:name="ag.access.Add_Edit_Cows" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Dairy" />
    </activity>
    <activity
        android:name="ag.access.Viewcows"
        android:label="@string/title_activity_viewcows"
        android:parentActivityName="ag.access.Add_Edit_Cows" >
        <intent-filter>
            <action android:name="ag.access.Viewcows" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Add_Edit_Cows" />
    </activity>
    <provider
        android:name="ag.access.cowsdb.provider.Cows_Provider"
        android:authorities="ag.access.cowsdb.provider.Cows_Provider">
        </provider>
</application>
</manifest>

Content Provider Java:

 package ag.access.cowsdb.provider;



 import ag.access.cowsdb.Cowsdatabase;
 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.text.TextUtils;
    public class Cows_Provider extends ContentProvider {

private Cowsdatabase cowsdbh;

private static final String Authority = 
        "ag.access.cowsdb.Cows_Provider";
private static final String Cows = "Cows";
public static final Uri Content_Uri = Uri.parse("content://" + Authority + "/" + Cows);
public static final int COWS = 1;
public static final int COWS_ID = 2;    
private static final UriMatcher cURIMatcher =
        new UriMatcher(UriMatcher.NO_MATCH);
static {
    cURIMatcher.addURI(Authority, Cows, COWS);
    cURIMatcher.addURI(Authority, Cows + "/#", COWS_ID);
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {

    int uriType = cURIMatcher.match(uri);
    SQLiteDatabase mysqldb = cowsdbh.getWritableDatabase();
    int rowsDeleted = 0;

    switch (uriType) {
    case COWS:
        rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, selection, selectionArgs);
        break;
    case COWS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
            rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, Cowsdatabase.Key_Cow + "=" + id, null);
        } else {
        rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, Cowsdatabase.Key_Cow + "=" + id + " and " + selection, selectionArgs);
        }
        break;
        default:
            throw new IllegalArgumentException("Unknow URI: " + uri);
}
    getContext().getContentResolver().notifyChange(uri, null);
    return rowsDeleted;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
    int uriType = cURIMatcher.match(uri);

    SQLiteDatabase mydb = cowsdbh.getWritableDatabase();

    long id = 0;
    switch (uriType) {
    case COWS:
        id = mydb.insert(Cowsdatabase.DATABASE_TABLE, null, values);
        break;
        default:
            throw new IllegalArgumentException("Unknow Uri: " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return Uri.parse(Cows + "/" + id);
}
@Override
public boolean onCreate() {
    cowsdbh = new Cowsdatabase(getContext(), null, null, 1);
    return false;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(cowsdbh.DATABASE_TABLE);

    int uriType = cURIMatcher.match(uri);

    switch (uriType) {
    case COWS_ID:
        qb.appendWhere(cowsdbh.Key_Cow + "=" + uri.getLastPathSegment());
        break;
    case COWS:
        break;
        default:
        throw new IllegalArgumentException("Unknown URI");

}
    Cursor cursor = qb.query(cowsdbh.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
    int uriType = cURIMatcher.match(uri);
    SQLiteDatabase mysqldb = cowsdbh.getWritableDatabase();
    int rowsUpdated = 0;

    switch (uriType) {
    case COWS:
        rowsUpdated = mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, selection, selectionArgs);
        break;
    case COWS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
            rowsUpdated =
                    mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, Cowsdatabase.Key_Cow + "=" + id, null);
        } else {
            rowsUpdated =
                    mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, Cowsdatabase.Key_Cow + "=" + id + " and " + selection, selectionArgs);
        }
        break;
        default:
            throw new IllegalArgumentException("Unknown URI:" + uri);
        }
      getContext().getContentResolver().notifyChange(uri, null);
      return rowsUpdated;
  }
  @Override
  public String getType(Uri uri) {
    // TODO Auto-generated method stub
    return null;
 }
   }

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:3)

在类中,您将Authority值设置为“ag.access.cowsdb.Cows_Provider”,而在Manifest文件中则不同“ag.access.cowsdb.provider.Cows_Provider”

请使用相同的权限值