How Android launches the browser

Source: Internet
Author: User

[Java]View Plaincopyprint?
  1. Intent Intent = New          Intent ();
  2. intent.setaction (" Android.intent.action.VIEW "
  3. uri url = uri.parse (" http://www.baidu.com "
  4. Intent.setdata (URL);
  5. StartActivity (Intent);

  

  
Specify the appropriate browser access

1. Specify the browser access that comes with Android

[Java]View Plaincopyprint?
  1. (" Com.android.browser ": packagename;" com.android.browser.BrowserActivity ": Start main activity)   
  2. Intent intent = new  intent ();           
  3. Intent.setaction (" Android.intent.action.VIEW "
  4. Uri content_url = uri.parse (" http://www.cnblogs.com "
  5. Intent.setdata (Content_url);              
  6. Intent.setclassname ("Com.android.browser","com.android.browser.BrowserActivity"    );  StartActivity (Intent);


2. Launch other browsers (of course, the browser must be installed on the machine)
You can invoke other browsers as long as you modify the following appropriate PackageName and master boot activity

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"

Third, open the local HTML file
When opening the local HTML file, be sure to specify a browser, but not in a way to browse, the sample code is as follows

  

[Java]View Plaincopyprint?
  1. Intent  intent =  new  intent ();  
  2. Intent.setaction (" Android.intent.action.VIEW "
  3. Uri content_url = uri.parse (" content://com.android.htmlfileprovider/sdcard/help.html "
  4. Intent.setdata (Content_url);              
  5. Intent.setclassname (" Com.android.browser " " com.android.browser.BrowserActivity "
  6. StartActivity (Intent);

The key point is to invoke the "content" filter.
Previously have in Win32 programming friend, may think in this form "file://sccard/help.html" whether can, can be very certain to tell you, the default browser setting is not to "file" this parse, If you want to allow your default Android browser to have this feature you need to modify the Manifest.xml file to the Android source code, and then compile your own browser to generate the appropriate APK package to re-install on the machine.

The general steps are as follows:

1, open the Packages/apps/browser/androidmanifest.xml file to add to the corresponding <intent-filter> back on it can
  

[Java]View Plaincopyprint?
  1. < intent-filter>  
  2.                  <action android:name=" Android.intent.action.VIEW " &NBSP;/>&NBSP;&NBSP;
  3.                  <category android:name=" Android.intent.category.DEFAULT " &NBSP;/>&NBSP;&NBSP;
  4.                  <category android:name=" Android.intent.category.BROWSABLE " &NBSP;/>&NBSP;&NBSP;
  5.                  <data android:scheme=" file " &NBSP;/>&NBSP;&NBSP;
  6. </intent-filter>

2, recompile packaging, installation, this way, the new browser will support the form of "file".

How Android launches the browser

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.