我一直在寻找近一天,这件事让我发疯。在android上找不到路径
我想打开一个连接到SQLite数据库我从Windows推到设备。
数据库现在是这个路径里面:
电话/安卓/数据/ MyApp.Droid /文件/ MyDB.db3
可以在不 '电话/ Android的' 我读认为。
当我尝试建立到数据库的连接时,我似乎无法找到路径。
这是我的代码,用于检索路径并创建连接。
public SQLite.SQLiteConnection GetConnection()
{
var sqliteFile = "MyDB.db3";
var dataPath = global::Android.OS.Environment.DataDirectory.AbsolutePath;
var dataPathExtension = @"MyApp.Droid/files";
var destination = Path.Combine(dataPath, dataPathExtension, sqliteFile);
//this outputs the following: /data/MyApp.Droid/files/MyDB.db3
//When I check my phone this is exactly when I can find the file.
return new SQLite.SQliteConnection(destination);
//It can't find the path/file.
}
数据库需要位于我可以从Windows访问的位置,而不需要设备生根。
任何人都可以向我解释为什么它找不到路径/文件,如果可能的话告诉我如何读取位置?
注:我不能从Windows访问任何 'Environment.SpecialFolder' 它似乎这给了我像一个路径:数据/用户/ 0/MyApp.Droid /文件/
此致,
Android以许多奇怪的方式存储文件。你应该看看“Android解析文件路径”或类似的东西。根据你的Android版本,文件类型等,这将是不同的。 或者你是幸运的,只是忘记将它存储在ExternalStorage并检查权限(可以是内部的,外部并不意味着SD卡,因为... Google不关心逻辑) –
您将不得不数据库文件在你的应用程序的沙箱外,下载dir,sdcard等。http://stackoverflow.com/questions/5858107/how-to-get-file-path-from-sd-card-in-android – SushiHangover