简体   繁体   English

如何访问 android 设备上的数据库文件 [Xamarin App with Entity Framework for SQLite]

[英]How to access a database file on android device [Xamarin App with Entity Framework for SQLite]

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.我是移动编程的初学者,我正在尝试在 Xamarin Forms 中创建一个数据库应用程序,有一个实体框架 SQLite 以便于使用数据库。 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:在 android 项目中,我实现了一个返回数据库路径的方法:

return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename);

this metod returns "/data/user/0/com.companyname.daily_app/files/DailyAppDatabase.db"此方法返回“/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).我想我应该在这里搜索一个数据库文件(我想得到这个文件并在 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.但是我不能使用模拟器,我的虚拟化系统不工作,我在物理无根 Android 7.0 设备上调试我的应用程序。 How I can do this?我怎么能做到这一点? I've looked at many similar topics like these:我看过许多类似的主题,例如:

How to access data/data folder in Android device? 如何访问 Android 设备中的数据/数据文件夹?

Retrieve database or any other file from the Internal Storage using run-as 使用 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 1)使用 adb shell 命令 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/ 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但我认为,这是解决问题的错误方法,得到一个异常“方法myOutput.write (...) is not supported. 也许有人遇到过这个问题并且可以提供帮助,我不想获得根访问,我喜欢 EntityFramework Core 中用于 SQLite 的代码优先方法

I found a solution, it was so difficult for me.我找到了解决方案,这对我来说太难了。 The following algorithm:以下算法:

1)making backup file (note the attribute android:allowBackup = true in your app manifest) 1)制作备份文件(注意应用清单中的属性 android:allowBackup = true )

adb backup -f "\location\on\local\drive" -noapk app.package.name

2) unpacking .ab file to.tar file using abe.jar 2) .ab file to.tar file using abe.jar解包为 .tar 文件

3) there are files and db file in the.tar folder 3).tar文件夹中有文件和db文件

maybe this will help someone in the future也许这会在未来帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android设备模拟器中访问我的应用程序的SQLite数据库进行调试 - How to access my app's SQLite database in android device emulator for debugging 如果该应用已卸载,如何将sqlite数据库保留在android设备上? - How to keep sqlite database on an android device if the app is uninstalled? 如何将 sqlite 数据库导出到 Android 设备上的 csv 文件? - How do you export an sqlite database to a csv file on an Android device? 从Android设备提取Sqlite数据库文件 - Extracting Sqlite Database file from Android Device 如何访问Android app沙箱存储下的SQLite数据库? - How to access an SQLite database under the Android app sandbox storage? 如何访问Android App中在SQLiteManager中创建的SQLite数据库? - How to access SQLite Database created in SQLiteManager in Android App? 使用 Cordova android 应用程序,我如何访问(读/写)Win10 设备共享文件夹中的 SQLite 文件? - With Cordova android app, how I can access (read/write) SQLite file at shared folder in Win10 device? 如何在android中访问数据库sqlite - how to access database sqlite in android 如何在Android中访问Sqlite数据库? - How to access the Sqlite Database in Android? 如何在 Xamarin 应用程序和 Java Android 应用程序之间共享 sqlite 数据库 - How do I share a sqlite database between a Xamarin app and Java Android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM