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.