2011-07-22 74 views
4

我试图创建一个自定义的内容提供商,我得到一个错误信息Android的内容提供商给未知的URL内容:// COM

未知的URL内容://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

+0

变化的android:name要.SampleContentProvider http://stackoverflow.com/questions/6152713/my-android-contentprovider -cant-find-contentresolver/6153147#6153147 – Selvin

+0

试过了,但我还是g等同样的错误 – Ramji

+0

你重写提供商中的'公共字符串getType(Uri uri)'? – Selvin

回答

4

在这里你去项目fixin'

http://esilo.pl/Yea.zip

几件事...... 雷诺的答案...但有一个再多个错误:

// 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); 
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> 
+0

这是很好的答案......但是有更多的错误 – Selvin