string DB_PATH = "/data/";
String DB_NAME = "AppDB.db";
string DBFile = "";
private void InitApp()
{
try
{
string db_File = DB_PATH + DB_NAME;
if (Android.OS.Environment.MediaMounted.Equals(Android.OS.Environment.ExternalStorageState))
{
var file = Android.OS.Environment.ExternalStorageDirectory;
string path = file.Path + DB_PATH;
if (System.IO.Directory.Exists(path) == false)
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
di.Create();
}
db_File = path + DB_NAME;
DBFile = db_File;
if (System.IO.File.Exists(db_File) == false)
{
const int maxReadSize = 256 * 1024;
byte[] content;
AssetManager assets = this.Assets;
using (BinaryReader br = new BinaryReader(assets.Open(DB_NAME)))
{
content = br.ReadBytes(maxReadSize);
}
FileStream fs = new FileStream(db_File, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(content);
bw.Close();
fs.Close();
}
}
}
catch (Exception ex)
{
ShowMessageBox(ex.Message);
}
}
|