Android developer _ How to call a browser to access webpages and HTML files

Source: Internet
Author: User

1. Start the default Android Browser

 

Intent intent = new intent ();
Intent. setaction ("android. Intent. Action. View ");
Uri content_url = URI. parse ("http://www.cnblogs.com ");
Intent. setdata (content_url );
Startactivity (intent );

In this way, android can call the default browser to access the mobile phone.


 

2. Specify the corresponding browser to access


1. Specify the android browser to access

("Com. Android. Browser": packagename; "com. Android. browser. browseractivity": Start the main activity)


Intent intent = new intent ();
Intent. setaction ("android. Intent. Action. View ");
Uri content_url = URI. parse ("http://www.cnblogs.com ");
Intent. setdata (content_url );
Intent. setclassname ("com. Android. Browser", "com. Android. browser. browseractivity ");
Startactivity (intent );

2. Start other browsers (of course, the browser must be installed on the machine)


You only need to modify the following packagename and the main activity to call other browsers.


 

Intent. setclassname ("com. Android. Browser", "com. Android. browser. browseractivity ");

UC Browser ":" com. UC. Browser "," com. UC. browser. activityupdate"

Opera: "com. Opera. Mini. Android", "com. Opera. Mini. Android. Browser"


Qq Browser: "com. Tencent. MTT", "com. Tencent. MTT. mainactivity"

 

3. Open a local HTML file

When opening a local HTML file, you must specify a browser instead of browsing it. The sample code is as follows:

 

Intent intent = new intent ();
Intent. setaction ("android. Intent. Action. View ");
Uri content_url = URI. parse ("content: // com.android.html fileprovider/sdcard/help.html ");
Intent. setdata (content_url );
Intent. setclassname ("com. Android. Browser", "com. Android. browser. browseractivity ");
Startactivity (intent );
 

The key point is that the filter "content" is called.

A friend who used to program in Win32 may think that this form of "file: // sccard/help.html" is acceptable. I can tell you for sure, the default browser setting does not parse the "File". To enable this function for your default Android browser, You need to modify manifest in the android source code. XML file, and then compile the browser code to generate the corresponding APK package to re-install it on the machine.

The general steps are as follows:

1. Open the packages/apps/Browser/androidmanifest. xml file and add it to the corresponding <intent-filter> file.

 

<Intent-filter>
<Action Android: Name = "android. Intent. Action. View"/>
<Category Android: Name = "android. Intent. Category. Default"/>
<Category Android: Name = "android. Intent. Category. browsable"/>
<Data Android: Scheme = "file"/>
</Intent-filter>
2. recompile, package, and install the tool. In this way, the new browser supports the "file" format.


If you are interested, try it.

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.