Android browser usage example details of calls uc opera qq browsers to access web pages

  • 2020-12-18 01:55:16
  • OfStack

This article illustrates the browser usage of Android. To share for your reference, the details are as follows:

1. Start the android default browser


Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("https://www.ofstack.com");
intent.setData(content_url);
startActivity(intent);

In this way, android can invoke the phone's default browser access.

2. Specify the appropriate browser access

1. Specify the browser access that comes with android

("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("https://www.ofstack.com");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);

2. Start another browser (which of course must be installed on the machine)

Other browsers can be invoked simply by modifying the following corresponding packagename and the main startup 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"

3. Open the local html file

When opening the local html file, 1 must specify a browser instead of browsing in mode 1, as shown in the sample code below


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 we called content, filter.

Used to have friends in win32 programming, may feel that with this kind of form "file: / / sccard help html" if you can, can certainly tell you, the default browser Settings is not for the parse "file", if you want to let you have the default browser android function need oneself to modify manifest android source code. The xml file, and then compile browser code generation corresponding apk packages to be installed 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 > You can do it in the back


<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, install, and in this way, the new browser supports the form "file".

I hope this article has been helpful in Android programming.


Related articles: