android save and read webpage
l Permission inmanifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
l Save web Page tosdcard:
//get file name
String fileName = webView1.copyBackForwardList().getCurrentItem()
.getTitle();
//save file to sdcard
webView1.saveWebArchive("/sdcard/"
+ Environment.DIRECTORY_DOWNLOADS + "/" + fileName
+ ".webarchivexml", false, newValueCallback<String>() {
@Override
public voidonReceiveValue(String value) {
if (value == null) {
//save failed
Toast.makeText(getApplicationContext(),
"savepage failed.", Toast.LENGTH_LONG).show();
} else {
//file saved, show message
Toast.makeText(getApplicationContext(), value
+ "has been saved", Toast.LENGTH_LONG).show();
}
}
});
l Read webpage archive saved:
//open saved file from sdcard
webView1.loadUrl("file:///sdcard/"
+ Environment.DIRECTORY_DOWNLOADS + "/" + fileName +".webarchivexml");
摘自 fhy_2008的专栏
补充:移动开发 , Android ,