There are two methods:
1. Code
As follows:
Intent
Intent = new
Intent ();
Intent. setaction ("android
. Intent. Action. View ");
Uri content_uri_browsers =
Uri. parse ("content: // com.android.html fileprovider/sdcard/123.html ");
Intent. setdata (content_uri_browsers );
Intent. setclassname ("com. Android. Browser ",
"Com. Android. browser. browseractivity ");
Startactivity (intent );
Suppose the local HTML file to be opened
Stored in the following path/sdcard/123.html
If an error occurs:
Unable to find explicit activity class {
Com. Google. Android. Browser/COM. Android. browser. browseractivity };
Have you declared this activity in your androidmanifest. xml?
Use
Intent. setcomponent (New componentname ("com. Android. Browser", "com. Android. browser. browseractivity "));
Replace
Intent. setclassname ("com. Android. Browser ",
"Com. Android. browser. browseractivity ");
As for the reason, there is no research on the reason for the time, and I hope to have a detailed explanation.
2. Use webview to implement:
First, add the webview control to the XML file in the layout folder.
<Webview
Android: Id = "@ + ID/wv1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
/>
Enter the following code in the main file:
Public
Class
Testdemo extends
Activity {
/** Called when the activity is first created .*/
@ Override
Public
Void
Oncreate (bundle savedinstancestate ){
Super
. Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Webview wview = (webview) findviewbyid (R. Id. wv1 );
Websettings Wset = wview. getsettings ();
Wset. setjavascriptenabled (true
);
// Wview. loadurl ("file: // android_asset/index.html ");
// Wview. loadurl ("content: // com.android.html fileprovider/sdcard/index.html ");
Wview. loadurl ("http://wap.baidu.com"
);
}
}
Explanation:
// Wview. loadurl ("file: // android_asset/index.html
");
-----
Open the index.html file under the assetdirectory of this package
// Wview. loadurl ("content: // com.android.html fileprovider/sdcard/index.html ");
-----
Open the index.html file for accessing sdks
// Wview. loadurl ("http://wap.baidu.com
");
-----
Open the HTML file of the specified URL