问题
My goal is writing a ContentProvider without an Activity. For testing I wrote a test - activity in a own app. For those who want to tell me that there is still a logger included in android, I know this.
Here is part of the ContentProvider
public static final String AUTHORITY = "de.xyz.android.log4android";
public static final int LOGGER_ARROW_URI_ID = 1;
public static final String ARROW_CONTENT_TYPE = 
    "vnd.de.xyz.android.cursor.dir/vnr.log";
public static final int LOGGER_ITEM_URI_ID = 2;
public static final String ITEM_CONTENT_TYPE = 
    "vnd.de.xyz.android.cursor.item/vnr.log";
public static final UriMatcher sUriMatcher;
static {
    sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    sUriMatcher.addURI(AUTHORITY, LOGGER_TABLE, LOGGER_ARROW_URI_ID);
    sUriMatcher.addURI(AUTHORITY, LOGGER_TABLE + "#", LOGGER_ITEM_URI_ID);
}
public static final Uri CONTENT_URI = Uri.parse("content://"
        + LogServiceProvider.AUTHORITY + "/logs");
public static final DefaultLogEntry LOG_ENTRY = null;
//Some more not important code
@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    synchronized (this) {
        try {
            long rowID = dbHelper.getWritableDatabase().insert(LOGGER_TABLE,
                    null, initialValues);
            if (rowID > 0) {
                Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
                getContext().getContentResolver().notifyChange(_uri, null);
                return _uri;
            }
        } catch (Exception ex) {
        }
        throw new SQLException("Failed to insert row into " + uri);
    }
}
//Some more not important code
So I also add the Content Provider Information to manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="de.xyz.android.logger"
          android:versionCode="1"
          android:versionName="1.0">
    <provider 
        android:name="de.xyz.android.logger.LogServiceProvider" 
        android:authorities="de.xyz.android.log4android"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-sdk android:minSdkVersion="4" /> 
</application>
Here Is the part out of my Client activity, that is in a seperate app.
ContentResolver cr = getContentResolver();
Uri getItem = Uri.parse("content://de.xyz.android.log4android/logs");
ContentValues values = new ContentValues();
values.put("level","WARNING");
values.put("time","1986-11-16");
values.put("message","FistTest");
values.put("owner","jsb");
values.put("file","testLog.java");
values.put("line","27");
Uri newItem = cr.insert(getItem, values);
LogCat tells me that TestClient cant find the ContentProvider
05-27 12:42:52.099: ERROR/ActivityThread(548): Failed to find provider info for de.xyz.android.log4android
Where is my error. In my opinion I did all mentioned in: Content Providers | Android. It would be nice if you could give me an hint. If you need more code fragments to understand ask me.
回答1:
<provider android:name=".LogServiceProvider"
          android:authorities="de.xyz.android.log4android"
          android:exported="true" />
should help :)
回答2:
One esoteric way in which this can fail is if you have a constructor defined on your content provider that takes an argument. That will cause the default 0 argument constructor to not exist. This causes the runtime registration of the provider to fail because the system cannot find a zero argument constructor in the class you specified under android:name in the manifest.
来源:https://stackoverflow.com/questions/6152713/my-android-contentprovider-cant-find-contentresolver