答案 0 :(得分:1)
您最好的选择是在您的SD卡中下载您的db 其他地方(即:/temp
目录。)
有关如何执行此操作的示例,请访问:http://www.androidsnippets.com/download-an-http-file-to-sdcard-with-progress-notification
然后将数据从临时目录中的数据库复制到实际数据库,最后删除下载的数据库。
有关如何执行此操作的示例,请访问:https://stackoverflow.com/a/10371472/2649012
这个不是一个完整的例子,你向正确的方向“踢”。
答案 1 :(得分:1)
试试这个来下载你的文件:
try {
URL url = new URL(" <URL HERE> ");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
String DatbasesPath = Environment.getDataDirectory() + "/data/" + getApplication().getPackageName() + "/databases/";
File file = new File(DatbasesPath, "mydb.db");
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
答案 2 :(得分:0)
在DownloadManager.Request
对象中使用setDestinationInExternalPublicDir方法更改目的地和名称。
或setDestinationUri
只做你想做的事。
文档here。