Android Developer Browser Usage example (invoke UC,OPERA,QQ browser to access Web page) _android

Source: Internet
Author: User

This example describes the browser usage of Android development. Share to everyone for your reference, specific as follows:

First, start the Android default browser

Intent Intent = new Intent ();
Intent.setaction ("Android.intent.action.VIEW");
Uri Content_url = Uri.parse ("http://www.jb51.net");
Intent.setdata (Content_url);
StartActivity (Intent);

In this way, Android can invoke the default browser access to the phone.

Second, specify the appropriate browser access

1, the designated Android browser with 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.jb51.net");
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 can invoke other browsers as long as you modify the following corresponding PackageName and master startup activity

Copy Code code as follows:
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"

Open a local HTML file

When you open a local HTML file, be sure to specify a browser, but not the way to browse, the specific example 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 to call the "content" this filter.

Previously have in Win32 programming friend, may feel in this form "file://sccard/help.html" is OK, can be very certain to say to you, the default browser setting is not to "file" this to parse, If you want your default Android browser to have this feature, you need to modify the Manifest.xml file yourself to the Android source code, and then compile your own browser codes to generate the appropriate APK packages to reinstall them on the machine.

The overall steps are as follows:

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

<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 packaging, installation, this way, the new browser to support the "file" this form.

I hope this article will help you with the Android program.

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.