I just created a demo to decompress the local zip file and use webview to display one of the html files and directly upload the code. If you need it, you can check it out.
Public class ZipActivity extends Activity {
Private static final String TAG = "HelloXmlActivity ";
Private WebView mWebView;
Private static LinkedHashMap <String, String> widgetInfoMap = new LinkedHashMap <String, String> ();
// Http://blog.csdn.net/com360/article/details/6618086
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
String zipfile = "/sdcard/abc.zip ";
Try {
Unzip (zipfile, "/sdcard/"); // yangguangfu/wujiali/
} Catch (Exception e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
MWebView = (WebView) findViewById (R. id. web );
MWebView. loadUrl ("file: // sdcard/abc/aaa.html"); // load the extracted html content here
}
/*
* This is the method for extracting ZIP files.
*
* @ ZipFileName: indicates the path of the file to be decompressed, including the file name;
*
* @ OutputDirectory: select the path you want to save;
*
*/
Private void unzip (String zipFileName, String outputDirectory)
Throws Exception {
ZipInputStream in = new ZipInputStream (new FileInputStream (zipFileName ));
ZipEntry z;
String name = "";
String extractedFile = "";
Int counter = 0;
While (z = in. getNextEntry ())! = Null ){
Name = z. getName ();
Log. d (TAG, "unzipping file:" + name );
If (z. isDirectory ()){
Log. d (TAG, name + "is a folder ");
// Get the folder name of the widget
Name = name. substring (0, name. length ()-1 );
File folder = new File (outputDirectory + File. separator + name );
Folder. mkdirs ();
If (counter = 0 ){
ExtractedFile = folder. toString ();
}
Counter ++;
Log. d (TAG, "mkdir" + outputDirectory + File. separator + name );
} Else {
Log. d (TAG, name + "is a normal file ");
File file = new File (outputDirectory + File. separator + name );
File. createNewFile ();
// Get the output stream of the file
FileOutputStream out = new FileOutputStream (file );
Int ch;
Byte [] buffer = new byte [1024];
// Read (ch) bytes into buffer
While (ch = in. read (buffer ))! =-1 ){
// Write (ch) byte from buffer at the position 0
Out. write (buffer, 0, ch );
Out. flush ();
}
Out. close ();
}
}
In. close ();
}
}
In this example, my abc.zip file is stored in sdcard, which contains two files. decompress the file and generate an abc folder. The folder contains two decompressed files, I used a webview to directly load an html file after learning about the compression, Which is rough, saving the file existence judgment, scanning the file name, file type, main. the xml file is also very simple. You can see the controls in the above Code. Here, the xml layout file is no longer written.
From andy Pan's column