Android automatically sets the default browser when it starts
Reference: http://blog.csdn.net/pediyasm/article/details/7987389
1. Set the principle of the default application
After the default application is set, the following information is added to the mobile phone/data/system/packages. xml file using the UC browser as an example:
- <Preferred-activities>
- <Item name = "com. UCMobile/. main. UCMobile" match = "200000" set = "2">
- <Set name = "com. UCMobile/. main. UCMobile"/>
- <Set name = "com. android. browser/. BrowserActivity"/>
- <Filter>
- <Action name = "android. intent. action. VIEW"/>
- <Cat name = "android. intent. category. DEFAULT"/>
- <Scheme name = "http"/>
- </Filter>
- </Item>
- </Preferred-activities>
2. Implementation Method. Two methods can be implemented: one is implemented in provision.apk, and the other is implemented in PackageManagerService. java. The Code is as follows:
- Private void addPreferredActivityForULauncher (){
- IntentFilter filter = new IntentFilter ();
- Filter. addAction ("android. intent. action. VIEW ");
- Filter. addCategory ("android. intent. category. DEFAULT ");
- Filter. addDataScheme ("http ");
- ComponentName preActivity = new ComponentName ("com. UCMobile", "com. UCMobile. main. UCMobile ");
- ComponentName [] set = new ComponentName [] {preActivity, new ComponentName ("com. android. browser", "com. android. browser. BrowserActivity ")};
- MSettings. mPreferredActivities. addFilter (
- New PreferredActivity (filter, 0x200000, set, preActivity ));
- MSettings. writeLPr ();
- }
- If (isFirstBoot ()){
- AddPreferredActivityForULauncher ();
- }
3. Use the mm command to generate services. jar and push it to the mobile phone/system/framework. At the same time, the uc browser is pre-installed into the system. Restore the factory settings to take effect.