私のアプリはリンクからデータベースをダウンロードする必要があります。データベースをダウンロードしてSDカードに保存するために使用するコードは次のとおりです。
public void DownloadBD() {
try {
URL url = new URL(
"http://mylink/dbHandler.axd?SqliteDbVersion=0");
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File SDCardRoot = Environment.getExternalStorageDirectory();
File file = new File(SDCardRoot, "DirLaguna.db");
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
int totalSize = urlConnection.getContentLength();
int downloadedSize = 0;
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = inputStream.read(buffer)) > 0) {
fileOutput.write(buffer, 0, bufferLength);
downloadedSize += bufferLength;
}
fileOutput.close();
location = file.getAbsolutePath();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
すべてが正常に動作しているように見えますが、現時点ではデータベースにクエリを実行したい (生のクエリを使用しています) テーブルが存在しないというエラーが表示されます。
その後、アプリケーションのデバッグを試みたところ、データベースが破損しているというエラーが表示されました。ダウンロード プロセスがデータベースを破損させていると思います。
共有するコードが不足している場合は、教えてください。
前もって感謝します!