android content provider gives Unknown URL content://com
Asked Answered
V

3

5

I am trying to create a custom content provider and I get a error message

Unknown URL content://com.example.test.samplecontentprovider/yay

I have the following info in my manifest and content provider

  <provider
    android:authorities="com.example.test.samplecontentprovider"
    android:multiprocess="true"
    android:name="com.example.test.SampleContentProvider"></provider>

AUTHORITY = "com.example.test.samplecontentprovider" 

where could I be wrong, please suggest.

I am also including the source code package here. http://www.fileserve.com/file/p4eNVgK

Vaasta answered 22/7, 2011 at 10:1 Comment(8)
change android:name to .SampleContentProvider #6153213Nordine
Tried that already, but I still get the same errorVaasta
did you override public String getType(Uri uri) in provider?Nordine
where are you getting error message ... could you provide some code ?Nordine
yes I did, but the compiler does not seem to even reach there, because I have a different error thrown up thereVaasta
fileserve.com/file/p4eNVgK, I have zipped and uploaded a project in the fileserve link. It is very small just 54 kbVaasta
@Nordine let us continue this discussion in chatVaasta
Please join the chat link, so we can chat thereVaasta
N
4

here you go project fixin'

http://esilo.pl/Yea.zip

few things ... Renaud answer ... but there are more errors:

// there is no such constructor ... Android looking for simple SampleContentProvider()
//public SampleContentProvider(Context context){
//  mContext=context;
//}

@Override
public boolean onCreate() {
    //so we move mContext initialization here
    mContext = getContext();
    dbHelper = new DatabaseHelper(mContext);
    return true;
}

next:

public static final class ContentProviderHelper  {
    private ContentProviderHelper() {}
    //private static final String BASE_PATH = "yay"; we don't need it
    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); //you dont need it + "/" + BASE_PATH);
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + 
                                                        "/vnd." + COMPANY_NAME + "." + TABLE_NAME;//yay it's stupid :P BASE_PATH;
    public static final String CONTENT_TYPE =   ContentResolver.CURSOR_DIR_BASE_TYPE + 
                                                    "/vnd." + COMPANY_NAME + "." + TABLE_NAME;//yay it's stupid :P BASE_PATH;
    public static final String ID = "_id";
    public static final String TITLE = "title";
    public static final String TEXT = "text";
}

next in test.java:

    Uri uri = getContentResolver().insert(
            // we should replace SampleContentProvider.ContentProviderHelper.CONTENT_URI with CONTENT_URI + TABLE_NAME
            Uri.withAppendedPath(SampleContentProvider.ContentProviderHelper.CONTENT_URI, SampleContentProvider.TABLE_NAME), values);
Nordine answered 22/7, 2011 at 12:2 Comment(0)
H
12

From the sources provided, you have made a mistake in defining your provider in AndroidManifest.xml: you need to define your provider within your application tag, i.e.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".test"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
        <provider
        android:authorities="com.example.test.samplecontentprovider"
        android:multiprocess="true"
        android:name="com.example.test.SampleContentProvider"></provider>
</application>
Hooke answered 22/7, 2011 at 11:49 Comment(0)
N
4

here you go project fixin'

http://esilo.pl/Yea.zip

few things ... Renaud answer ... but there are more errors:

// there is no such constructor ... Android looking for simple SampleContentProvider()
//public SampleContentProvider(Context context){
//  mContext=context;
//}

@Override
public boolean onCreate() {
    //so we move mContext initialization here
    mContext = getContext();
    dbHelper = new DatabaseHelper(mContext);
    return true;
}

next:

public static final class ContentProviderHelper  {
    private ContentProviderHelper() {}
    //private static final String BASE_PATH = "yay"; we don't need it
    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); //you dont need it + "/" + BASE_PATH);
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + 
                                                        "/vnd." + COMPANY_NAME + "." + TABLE_NAME;//yay it's stupid :P BASE_PATH;
    public static final String CONTENT_TYPE =   ContentResolver.CURSOR_DIR_BASE_TYPE + 
                                                    "/vnd." + COMPANY_NAME + "." + TABLE_NAME;//yay it's stupid :P BASE_PATH;
    public static final String ID = "_id";
    public static final String TITLE = "title";
    public static final String TEXT = "text";
}

next in test.java:

    Uri uri = getContentResolver().insert(
            // we should replace SampleContentProvider.ContentProviderHelper.CONTENT_URI with CONTENT_URI + TABLE_NAME
            Uri.withAppendedPath(SampleContentProvider.ContentProviderHelper.CONTENT_URI, SampleContentProvider.TABLE_NAME), values);
Nordine answered 22/7, 2011 at 12:2 Comment(0)
C
1

I tried to find any resolve about this, and i rewrite provider tag on my android manifest like this :

<provider
    android:name=".database.FVProv"
    android:authorities="com.cevin.sukafilm4"
    android:exported="true"
    android:readPermission="com.cevin.sukafilm4.READ_DATABASE"
    android:writePermission="com.cevin.sukafilm4.WRITE_DATABASE" />

Hope it will help you

Czerny answered 31/8, 2019 at 5:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.