Failed to find provider info for 'ContentProvider'
I have a problem that I just cannot figure out. I am using Eclipse to create my own Content Provider but keep getting the following error:
[..] ERROR/ActivityThread(1051): Failed to find provider info for my.package.provider.countrycontentprovider
Code found here: http://codepad.org/Rx00HjHd
Main parts:
public class CountryContentProvider extends ContentProvider {
public static final String PROVIDER =
"my.package.provider.countrycontent开发者_C百科provider";
public static final Uri CONTENT_URI =
Uri.parse("content://" + PROVIDER + "/country");
// ...
@Override
public boolean onCreate() { return true; }
// ...
}
// from my activity
ContentResolver resolver = getContentResolver();
Cursor c = resolver.query(CountryContentProvider.CONTENT_URI,
null, null, null, null);
// AndroidManifest.xml
<provider
android:name="my.package.provider.CountryContentProvider"
android:authorities="my.package.provider.countrycontentprovider" />
I have added the provider to the manifest and return true from the onCreate
function. I use the CountryContentProvider.CONTENT_URI
in my activity to get the Content from my provider, but I just keep getting that error message. I have removed and added the code three times (in case of eclipse melt down) to no avail.
I was able to reproduce your problem when I moved <provider> out of the <application>...</application> tag. Eclipse didn't say anything like error or warning.
Fortunately this issue is detected by Android Lint starting from ADT 20.
It worked for me only after specifying full path in Authorities
tag in manifest file (see SearchableDictionary sample code in SDK).
<provider android:name=".DictionaryProvider"
android:authorities="com.example.android.searchabledict.DictionaryProvider">
Inside your B-app which has the contentresolver, add this in the AndroidManifest.xml, outside application-tag
<queries>
<provider android:authorities="com.authoritiesname.in.contentprovider.app" />
</queries>
Setting the exported attribute to true in the provider tag in the manifest worked for me :
android:exported="true"
According to the documentation(http://developer.android.com/guide/topics/manifest/provider-element.html#exported), export is required only if the provider is to be available for other applications. But this is the only solution that worked for me.
The android:authorities= in the XML file is the content authority that is located in the contract class that you probably built. The content authority is added to the scheme to make the base content URI. Plain English, the reverse domain you used to make your app no caps here com.domain.sub.appName.
The android:name is the folder plus class your provider is named, do not forget the dot .folder.ProviderClassContentAuthorityIsIn.
Hope this helps :)
you have a capital letter and on the other line, one lowercase letter.
android:name= "my.package.provider.-C-ountryContentProvider" android:authorities="my.package.provider.-c-ountrycontentprovider"
it must be the same everywhere.
public static final String PROVIDER =
"my.package.provider.countrycontentprovider";
Register your provider in the Android Manifest
<provider
android:authorities="your_content_authority"
android:name="yourProviderClass"/>
精彩评论