I've had this problem and learned that in order to add a second content provider, I had to:
- Define the second provider in the Androidmanifest.xml file. Set the android:authority to the full name of the package and class.
- Use the authority as the URL
The authority for each provider must be unique and the URL for each provider must match the authority. The URL must be all lowercase as well.
Here is a hypothetical configuration:
AndroidManifest.xml
<application>
<provider android:name="com.acme.ProviderOne"
android:authorities="com.acme.providerone" />
<provider android:name="com.acme.ProviderTwo"
android:authorities="com.acme.providertwo" />
</application
src/com/acme/providerone.java
package com.acme
import android.content.ContentProvider;
public class ProviderOne extends ContentProvider {
public static final Uri CONTENT_URI = Uri.parse("content://com.acme.providerone/objects");
private static final int ALLROWS = 1;
private static final int SINGLE_ROW = 2;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.acme.providerone", "objects", ALLROWS);
uriMatcher.addURI("com.acme.providerone", "objects/#", SINGLE_ROW);
}
}
src/com/acme/providertwo.java
package com.acme
import android.content.ContentProvider;
public class ProviderTwo extends ContentProvider {
public static final Uri CONTENT_URI = Uri.parse("content://com.acme.providertwo/objects");
private static final int ALLROWS = 1;
private static final int SINGLE_ROW = 2;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.acme.providertwo", "objects", ALLROWS);
uriMatcher.addURI("com.acme.providertwo", "objects/#", SINGLE_ROW);
}
}