如何保存.HTML页/文件中的应用程序的数据库中的android?数据库中、应用程序、文件、HTML

由网友(遇见花开)分享简介:我现在工作的一个应用程序,它可以作为一本书,堆栈,用户可以阅读他们的选择,现在是什么我做的是,显示了我所做的html页面的书籍,在网页视图在我的应用程序。现在,该应用程序只有当用户有他的电话全时网络连接。究竟我要的是当他们第一次打开应用程序,他们需要互联网连接,然后应用程序应该能够下载该网页并将其存储在本地数据库...

我现在工作的一个应用程序,它可以作为一本书,堆栈,用户可以阅读他们的选择,现在是什么我做的是,显示了我所做的html页面的书籍,在网页视图在我的应用程序。 现在,该应用程序只有当用户有他的电话全时网络连接。 究竟我要的是当他们第一次打开应用程序,他们需要互联网连接,然后应用程序应该能够下载该网页并将其存储在本地数据库中,以便用户可以读取它以后无需任何互联网连接。 那么,有没有下载HTML页面,并将其存储在本地数据库中,以便用户可以使用,即使他没有连接到互联网?应用程序任何可能的方式 如果需要的话是我的选择:我的code在这里。 任何最小的提示或帮助将是真正伟大的,因为我长期以来现在困在这里:(的

I am right now working on an app which works as a book-stack,where user can read books of their choice,now what i am doing is,displaying the html pages that i've made,in a web-view in my application. Now this application works only if the user has full time internet connection on his phone. What exactly i want is when they first open the application,they would need internet connection and then the app should be able to download that page and store it in local database so the user can read it later on without having any internet connect. So is there any possible way to download the html page and store it in local database so user can use the app even if he is not connected to internet? I can post my code here if needed be. Any smallest tip or help would be really great as i am stuck here since long now:(

修改1:

所以,我成功地从网站上下载的HTLM页面,但现在我面临的问题是,我看不到任何下载的HTML的图像。有什么可以为这是一个妥善的解决办法?

So i successfully downloaded the HTLM page from the website,but now the problem that i am facing is,that i cannot see any of the images of the downloaded html. What can be a proper solution for this?

推荐答案

下面有什么的意思本地数据库

preferred方法是下载网页中的任何内部存储 (/<数据/数据​​/< application_package_name>)(默认情况下,非植根​​设备是专用于您的应用程序)或外部存储 (公共访问)。然后是指从存储区页面时用户设备还没有一个互联网连接(离线模式)。

Preferred way is download your pages in either Internal Storage(/<data/data/<application_package_name>) (by default on non rooted device is private to your application) or on External Storage(public access). Then refer the pages from that storage area when user device has not a internet connection (offline mode).

更新:1

要存储这些页面,则可以使用简单的文件读/在Android的写操作。

To store those pages, you can use simple File read/write operation in Android.

例如:

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

这个例子存储文件的 hello_file 在应用程序内部的存储目录。

This example store file hello_file in your application's internal storage directory.

更新:2 下载网页内容

HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.xxxx.com");
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";

BufferedReader reader = new BufferedReader(
    new InputStreamReader(
      response.getEntity().getContent()
    )
  );

String line = null;
while ((line = reader.readLine()) != null){
  result += line + "n";
}

//现在您对结果加载整个HTML变量

// Now you have the whole HTML loaded on the result variable

这么写会导致文件变量,用我的更新1 code。简单..: - )

So write result variable in File, using my update 1 code. Simple.. :-)

不要忘了在你的Andr​​oid应用程序的清单文件中添加这两个权限。

Don't forget to add these two permission in your android application's manifest file.

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.INTERNET"></uses-permission>
阅读全文

相关推荐

最新文章