Hi guys, I have been following this tutorial in its entirety, on how to store data in a local database. On iOS everything works fine, unfortunately on android i get an exception upon creating a table in my database file.. The method for creating the table is:
public CalcDatabase(string dbPath) { database = new SQLiteAsyncConnection(dbPath); database.CreateTableAsync<Calculation>().Wait(); }
And my custom class for getting the database path on Android is as follows:
public class LocalFileHelper : IFileHelper { public string GetLocalFilePath(string filename) { var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); path = Path.Combine(path, filename); if(!Directory.Exists(path)) { Directory.CreateDirectory(path); } return path; } }
This is the error that im getting from SQLite:
Could not open database file: /data/user/0/com.companyname.XX/files/Calculation.db3 (CannotOpen)
I have tried targeting several different APIs, i have tried to clean and rebuild my solution, and i have tried to reinstall the SQLite-net-pcl NuGet packages across the whole solution.. Nothing works..
I think this is problem with SQLite Nuget packages because these packages are not supported to latest android versions. Therefore i was created my own SQLite database using SQLiteOpenHelper class inheritance. But in case of PCL try another package instead of Frank Krueger packages.
For Example
https://c-sharpcorner.com/article/xamarin-android-develop-sqlite-database-using-sqliteopenhelper/
Answers
I think this is problem with SQLite Nuget packages because these packages are not supported to latest android versions. Therefore i was created my own SQLite database using SQLiteOpenHelper class inheritance. But in case of PCL try another package instead of Frank Krueger packages.
For Example
https://c-sharpcorner.com/article/xamarin-android-develop-sqlite-database-using-sqliteopenhelper/
Thank you for your answer @Ahsan_Siddique. For some strange reason I once again cleaned my solution, rebuilt it and added the following two permissions to my AndroidManifest.xml once again:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This time it works.. Very strange!