android内容提供商提供未知的URL内容:// com

时间:2011-07-22 10:01:38

标签: android android-contentprovider

我正在尝试创建自定义内容提供商,但收到错误消息

未知网址内容://com.example.test.samplecontentprovider/yay

我的清单和内容提供商

中有以下信息
  <provider
    android:authorities="com.example.test.samplecontentprovider"
    android:multiprocess="true"
    android:name="com.example.test.SampleContentProvider"></provider>

AUTHORITY = "com.example.test.samplecontentprovider" 

我可能在哪里错,请建议。

我也在这里包含源代码包。 http://www.fileserve.com/file/p4eNVgK

3 个答案:

答案 0 :(得分:10)

根据提供的来源,您在AndroidManifest.xml中定义提供程序时出错:您需要在应用程序标记中定义提供程序,即

<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>

答案 1 :(得分:4)

这里你去项目fixin'

http://esilo.pl/Yea.zip

很少的东西......  Renaud回答......但还有更多错误:

// 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;
}

下:

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";
}

下一个在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);

答案 2 :(得分:1)

我试图找到有关此问题的任何解决方法,并且在我的android清单上重写了provider标记,如下所示:

<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" />

希望对您有帮助