sqlite - Xamarin Android - 在哪里存储本地数据库以便我可以查看它

标签 sqlite xamarin xamarin.android xamarin.forms

我目前正在使用此代码将本地 sqlite 数据库保存在 Environment.GetFolderPath(Environment.SpecialFolder.Personal) 中。

现在我正在尝试将数据库复制到我的电脑上,以便我可以查看其中的内容。但除非它已root,否则我无法看到该文件夹​​。

哪里是保存数据库的最佳位置,以便我可以时不时地查看它?

这是我的 android DB 代码:

[assembly: Dependency(typeof(SQLite_Android))]

namespace AppName.Droid
{
    public class SQLite_Android : ILocalDb.Interfaces.ILocalDb
    {
        #region ISQLite implementation
        public SQLite.SQLiteConnection GetConnection()
        {
            var sqliteFilename   = "MyDb.db3";
            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var path             = Path.Combine(documentsPath, sqliteFilename);
            // Create the connection
            var conn             = new SQLite.SQLiteConnection(path);
            // Return the database connection
            return conn;
        }
        #endregion
    }
}

最佳答案

您可以使用外部存储选项:

        var sqliteFilename = "MyDb.db3";
        var extStoragePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
        var path = Path.Combine(extStoragePath, "MyNewFolder");
        var filename = Path.Combine(path, sqliteFilename);

        // Create the connection
        var conn = new SQLite.SQLiteConnection(path);
        // Return the database connection
        return conn;

这样文件将通过文件资源管理器可见

关于sqlite - Xamarin Android - 在哪里存储本地数据库以便我可以查看它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40236946/

相关文章:

python - 在 Apache/mod_wsgi 上运行 Django 时出错

android - 通过转换器将多个属性绑定(bind)到一个值

c# - 膨胀通用/模板化自定义 View

c# - Xamarin:构建时出错 -> 无效的文件路径 'obj\Debug\90\res\views\layouttest.xml'

android - 应用程序可以包含用户可以控制应用程序权限的页面吗?

c# - Xamarin : Android : System. UnauthorizedAccessException:拒绝访问路径

javascript - Sqlite html5在插入时复制记录

java - Java 应用程序如何在本地为用户创建和管理数据库?

c# - ObjectContext ConnectionString Sqlite

c# - 使用 shell 时如何更改 iOS 中状态栏的颜色