I need to create a sqlite db at a specific location in android where i can access it easily using a file explorer. I do not want the sqlite db created to be in the default /data
Solved. Using SushiHangover's method,there is an addition step that needs to be done so that the app can access the storage as below:
After deploying your app into android device:
Settings->[your App]
You could setup a copy function to copy/move your private/sandboxed SQLite file to a public directory of the device, something like:
public void CopyDBToSdCard(string dbName)
{ File.Copy(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), dbName),
Path.Combine(Android.OS.Environment.DirectoryDownloads, dbName));
}
Note: This is using native Android API to obtain the Downloads dir, so you could do this via a Forms dependency service.
Note: Your app would need external storage permissions (manifest and runtime-based)
You could just directly use a public storage area on the device, such as Downloads, Documents, etc. Your app would need manifest/runtime permission to access those locations.
var DBFile = Path.Combine(Android.OS.Environment.DirectoryDownloads,"Test.db");
You could just hard-code the public directory path for debugging (do not hardcode the path in a production app as different devices could have different paths, use the Android APIs to dynamically obtain the correct one for the device that it is running on).
Use adb shell
to obtain the correct path, ie:
adb shell ls /sdcard
Example:
var DBFile = Path.Combine("/sdcard/Download","Test.db");
Note: Again your app needs manifest/runtime permissions for read/write access to these locations