Android browser startup Method

Source: Internet
Author: User

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.


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.