Android browser startup Method
Start the default android Browser
Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri url = Uri.parse("http://www.baidu.com"); intent.setData(url); startActivity(intent);
Specify the corresponding browser 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.htmlfileprovider/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 You can do it later.
2. recompile, package, and install the tool. In this way, the new browser supports the "file" format.