I have a strange situation where I developed an Android App for a Samsung Tablet that is not working as intended. The User registration step (first step of the app) is not working and is generating a null error.
During the development phase, the MAUI Blazor Hybrid App was thoroughly tested on Windows and Samsung tablets; all emulators ran successfully as well. However, after deploying (a full install of the .apk file) the App on the same development Tablet, the App launched successfully but the user registration failed with a Null error. It seems as though the database is not getting found (created) as it should or did during development.
I am registering the database with the following path:
public class SQLiteDatabase:DbContext
{
public static string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ActivityData.db3");
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Filename={dbPath}");
}
}
// and properly setup the injection service in the MauiProgram.cs:
builder.Services.AddSingleton<SQLiteDatabase>();
Is there a special way to setup the database for Android? What else can I do to get this working?
Maui provide the local database for developers to use. You can check this document to use SQLite NuGet package.
First, you need to add the SQLite NuGet package and config the data. The sample project includes a Constants.cs file that provides common configuration data.
Second, you need to create a database access class.
Last, you can use the methods below to manipulate the data.