.html文件保存到使用OkHttp LIB内部存储 [英] Save .html file into internal storage using OkHttp lib

查看:233
本文介绍了.html文件保存到使用OkHttp LIB内部存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid和我试图创建的应用程序,节省的的.html 页到内部存储在以后打开它的WebView 。我想这样做,使用 OkHttp 库,但是,我不知道该怎么做。也许有一些机会,让页面code。在字符串,并存储成html?请帮助我。

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.

推荐答案

我的工作类似的东西,这是我救了我。

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");
        }
    }
});

这篇关于.html文件保存到使用OkHttp LIB内部存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆