I'm beginner in mobile programming, I'm trying to create a database application in Xamarin Forms, there is an Entity Framework SQLite for easy work with the database. After reading the articles I configuring my app so:
public partial class App : Application
{
public const string DbFileName = "DailyAppDatabase.db";
string dbPath = DependencyService.Get<IPath>().GetDatabasePath(DbFileName);
public App()...
}
In android project I implemented a method that returns the path to the Database:
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename);
this metod returns "/data/user/0/com.companyname.daily_app/files/DailyAppDatabase.db"
I think I should search a database file here(I want to get this file and open it in SQLite DB Browser). But I can't use emulators, my virtualization system is not working, I debug my app on physical unrooted Android 7.0 device. How I can do this? I've looked at many similar topics like these:
How to access data/data folder in Android device?
Retrieve database or any other file from the Internal Storage using run-as
but found no answer, I really need help, I tried following method:
1) using adb shell command chmod 666 /data/user/0/com.companyname.daily_app/files/DailyAppDatabase.db
2) adb shell -> run-as com.your.packagename -> cp /data/data/com.your.packagename/
But result of these commands on my device is permission denied, I tried this method:
string _databasePath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "DailyAppDatabse.db");
if (!File.Exists(_databasePath))
return;
Stream myInput = new FileStream(_databasePath, FileMode.Open);
Stream myOutput = Assets.Open("database.db");
byte[] buffer = new byte[1024];
int b = buffer.Length;
int length;
while ((length = myInput.Read(buffer, 0, b)) > 0)
{
myOutput.Write(buffer, 0, length);
}
myOutput.Flush();
myOutput.Close();
myInput.Close();
But i Think, this is the wrong way to solve the problem, get an exception "method myOutput.write (...) is not supported. Maybe someone has met this problem and can help, I don't want to get a root access and I like code-first approach in EntityFramework Core for SQLite