Search code examples
androidandroid-contentprovider

Custom content provider: error from the emulator (failed to find provider info)


So I created a simple content provider, but I've got an error :

Failed to find provider info for com.b1.BooksContentProvider

I have 2 AVD names for 2.2 and 3.2 versions (I wrote random names for both of them)
3.2 because I use the v4 Fragment support
So, I don't know if the problem comes from the manifest, or from the version I'm using to launch the emulator.

here's my manifest file:

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

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".MyBooksActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/mt_books" />
                <data android:mimeType="vnd.android.cursor.dir/mt_books" />
            </intent-filter>
        </activity>
        <provider
            android:authorities="com.b1.BooksContentProvider"
            android:name="com.b1.BooksContentProvider"></provider>

    </application>

</manifest>

and the first part of my content provider :

public class BooksContentProvider extends ContentProvider {

    BooksDataBase mDB;
    private static final String AUTHORITY = "com.b1.MyBooksActivity";
    private static final String BASE_PATH = "books";
    public static final Uri CONTENT_URI = Uri.parse("content:// " + AUTHORITY + "/" + BASE_PATH);
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
        + "/mt_books";
    public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
        + "/mt_books";

    private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    private static final int BOOK_DIR = 101;
    private static final int BOOK_ITEM = 102;

    static
    {
        sURIMatcher.addURI(AUTHORITY, BASE_PATH, BOOK_DIR);
        sURIMatcher.addURI(AUTHORITY, BASE_PATH+"/#", BOOK_ITEM);
    }

Thanks for your help


UPDATE


Ok, one of the possible mistake was :
i forgot to "import" the different classes
also, in the fragment XML : the LinearLayout did not work, i had to put a "TextView" alone in the XML


Solution

  • private static final String AUTHORITY = "com.b1.MyBooksActivity";
    

    That is not the same authority as you have in your <provider> element:

    <provider
            android:authorities="com.b1.BooksContentProvider"
            android:name="com.b1.BooksContentProvider"></provider>
    

    They need to match.