is android:exported="true" required for internal use of content provider
Asked Answered
O

2

9

I have defined a provider in my application manifest :

<provider
    android:authorities="com.example.myapp.provider"
    android:name="com.example.myapp.MyProvider">
</provider>

The provider is required only to be used within the application. But I get the below error when i try to run my activity :

Failed to find provider info..

But it works perfectly if i simply set the export attribute of the provider in the manifest :

android:exported="true" 

So my question is why is this required? Because, 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. Am i doing something wrong?

[Edit] : Suprisingly, the error has disappeared now even after removing the exported attribute, without making any other changes. I have no clue why it is working now. Probably some stupid mistake from my side. I leave this question open in hope of getting any clues as to what must have gone wrong.

[Edit] : I am facing this issue again with a receiver this time. So it was not a mistake from my side, as i assumed in my previous edit. I suspect something is wrong in the ADT build tool.

Optimist answered 1/6, 2014 at 7:44 Comment(2)
your authorities tag is not the same as your contentProvier (MyProvider vs provider). On doc says <i>Typically, it's the name of the ContentProvider subclass that implements the provider</i>Total
I did not really understand your comment. "MyProvider" is the name of my content provider class, which is in the package "com.example.myapp". And that's what i have specified for the "android:name" attribute. I named the "android:authorities" value randomly. I don't have any class named "provider". Anyway i don't think the name is a problem since the same names work when the provider is exported.Optimist
H
2

Make sure your <provider> tag is inside the <application>...</application> tags.

<application>
    ...
    <provider
        android:authorities="com.ingamedeo.databasetest.contentprovider"
        android:name=".db.ContentProviderDb"
        android:exported="false">            
    </provider>
</application>
Huan answered 2/6, 2014 at 17:35 Comment(1)
Look at this: #18464267Huan
S
-1

Update: You can no longer set

android:exported="true"

you will encounter java.lang.SecurityException: Provider must not be exported exception.

Shame answered 1/8, 2019 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.