我一直在尋找近一天,這件事讓我發瘋。在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