How to open a local HTML file in the android Browser

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.