Save .html file into internal storage using OkHttp lib

↘锁芯ラ 提交于 2019-12-13 00:47:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!