问题
I'm new to android and I'm trying to create app that save's .html page into internal storage to open it later in the WebView. I want to do that using OkHttp library but, I don't know how to do that. Maybe there is some opportunity to get code of the page in the String and store it into html? Help me please.
回答1:
I am working on something similàr and this is how I saved mine.
String url = "http://stackoverflow.com/questions/33056097/save-html-file-into-internal-storage-using-okhttp-lib#";
OkHttpClient client = new OkHttpClient();
final String url = sharedText;
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Log.e("APp", e.toString());
}
@Override
public void onResponse(Response response) throws IOException {
if(response.isSuccessful()){
output = response.body().string();
//You can then save the output in your database
}else {
//You can return an error since the response was not successful
Log.e("APp", "Error");
}
}
});
来源:https://stackoverflow.com/questions/33056097/save-html-file-into-internal-storage-using-okhttp-lib