Home > Java > javaTutorial > Android calls the system's default browser access method

Android calls the system's default browser access method

高洛峰
Release: 2017-01-17 15:00:50
Original
2088 people have browsed it

1. Start the android default browser

In this way, android can call the default browser of the mobile phone to access.

2. Specify the corresponding browser to access

1. Specify the browser that comes with android to access

( “com.android.browser”:packagename ;“com.android.browser.BrowserActivity”:启动主activity)
Intent intent= new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);
Copy after login

2. Start other browsers ( Of course, the browser must be installed on the machine)

Just modify the following corresponding packagename and main startup 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 using method one to browse. The specific 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);
Copy after login

The key point is to call the "content" filter.

Friends who have programmed in win32 before may wonder whether it is possible to use this form of "file://sccard/help.html". I can tell you with certainty that the default browser settings do not parse "file". If you want your default android browser to have this function, you need to modify the manifest.xml file in the android source code, and then compile it yourself. The browser code generates the corresponding apk package to reinstall 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

<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>
Copy after login

2. Recompile, package and install. In this way, the new browser will support the form of "file"

If you are interested, you can try it

The above content is the method introduced by the editor to access the default browser of the Android system. I hope it will be helpful to everyone! Please pay attention to the PHP Chinese website for related articles on the method of calling the default browser of the Android system!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template