I am working on a Solution in Xamarin which contains at least 4 different Android Applications.
My Goal is to create a shared content provider for all of these four apps so that I can have the Master data in one place (If an application updates that data, I can get that updated version in another app).
In Visual Studio, I have create a PCL project where I have defined the Content provider (which I can reference in all applications and do the CRUD operations).
My Content Provider is as follows:
namespace com.cybertron.android.Provider
{
public class SectionProvider : ContentProvider
{
SectionDatabase sectDb;
public const string AUTHORITY = "com.cybertron.android.Provider.SectionProvider";
public const string SECTIONS_MIME_TYPE = ContentResolver.CursorDirBaseType + "/vnd.com.cybertron.android.sections";
public const string SECTION_MIME_TYPE = ContentResolver.CursorItemBaseType + "/vnd.com.cybertron.android.section";
static string BASE_PATH = "sections";
static UriMatcher uriMatcher = BuildUriMatcher();
public static readonly Android.Net.Uri CONTENT_URI = Android.Net.Uri.Parse("content://" + AUTHORITY + "/" + BASE_PATH);
const int GET_ALL = 0;
const int GET_ONE = 1;
public static class SectionConsts
{
public const string SectNo = "SectNo";
public const string KeyPos = "Key";
public const string Date = "Date";
public const string UnitID = "UnitID";
}
static UriMatcher BuildUriMatcher()
{
var matcher = new UriMatcher(UriMatcher.NoMatch);
matcher.AddURI(AUTHORITY, BASE_PATH, GET_ALL);
matcher.AddURI(AUTHORITY, BASE_PATH + "/#", GET_ONE);
return matcher;
}
public override bool OnCreate()
{
sectDb = new SectionDatabase(Context);
return true;
}
public override string GetType(Android.Net.Uri uri)
{
switch (uriMatcher.Match(uri))
{
case GET_ALL:
return SECTIONS_MIME_TYPE; // list
case GET_ONE:
return SECTION_MIME_TYPE; // single item
default:
throw new Java.Lang.IllegalArgumentException("Unknown Uri: " + uri);
}
}
.
.
.
}
}
I have referenced my project in my Xamarin Application project. I did not put the ContentProvider
attribute because I learned that gives out INSALL_FAILED_CONFLICT
error if two applications use the same one. Instead I put that in the manifest file as follows:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cybertron.android.bluecork"
android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" />
<application android:label="com.cybertron.android.bluecork.blueapp">
<provider
android:name="com.cybertron.android.Provider.SectionProvider"
android:authorities="com.cybertron.android.Provider.SectionProvider"
android:exported="true" />
</application>
</manifest>
When I try to debug this application I get an error up front (when the app starts in the emulator)
java.lang.RuntimeException: Unable to get provider com.cybertron.android.Provider.SectionProvider:
java.lang.ClassNotFoundException: Didn't find class com.cybertron.android.Provider.SectionProvider on path: DexPathList......
Can anyone tell me why I am getting this error. Secondly, I would like to know if it is possible for multiple applications to share one database on Android Systems?
Thanks,