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);
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);
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.
<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 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!