Issue
The situation is that I have a MainFragment
(extends a ListFragment
, implements LoaderManager.LoaderCallbacks<Cursor>
) which is called from MainActivity
. A new activity DetailsActivity
is called from that fragment to display the content of a certain item in a list view getting the id as an intent argument. How can I getContentResolver()
to access its methods using a Uri?
The error right now I get from accessing content resolver is:
`java.lang.IllegalArgumentException: Unknown URL content://com.xxxx.words.contentprovider/words`
uri = Uri.parse(MainContentProvider.CONTENT_URI.toString());
getContentResolver().insert(uri, contentValues);
CONTENT_URI = Uri.parse("content://" + "com.xxxx.words.contentprovider" + "/" + "words");
android manifest file:
<provider
android:authorities="com.xxxx.words.contentprovider.MainContentProvider"
android:name=".contentprovider.MainContentProvider"/>
or should i just return a Bundle
from that DetailsActivity
and access the content provider in the initial fragment?
Solution
The error right now I get from accessing content resolver is
That is because your Uri
does not match your android:authorities
. Your android:authorities
is com.xxxx.words.contentprovider.MainContentProvider
. Your Uri
uses com.xxxx.words.contentprovider
. These are not the same, and they need to be the same.
Also, please add android:exported
to your <provider>
, set to true
(if third-party apps should have complete access to the provider) or false
(if they should not).
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.