Clearing and setting the default home application

前端 未结 4 2013
情话喂你
情话喂你 2020-11-29 00:18

How in the world does Nova manage this? I\'m literally trying to do exactly the same thing: provide users with a button to press to clear and pick their new default launcher

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 01:04

    The code to do this is actually just a very clever work around.

    When a component with

            
    

    is enabled, generally from an install of a new home application, the default home app gets cleared.

    To take advantage of this by creating an empty activity with the home component like this.

    
                
                    
                    
                    
                
                 
    

    When you want to set your new default, you enable this component, then call the home intent and then disable your fake home component again.

    public static void makePrefered(Context c) {
           PackageManager p = c.getPackageManager();
           ComponentName cN = new ComponentName(c, FakeHome.class);
           p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    
           Intent selector = new Intent(Intent.ACTION_MAIN);
           selector.addCategory(Intent.CATEGORY_HOME);            
           c.startActivity(selector);
    
           p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
       }
    

    The end result is that the system thinks a new home app was installed, so the default is cleared allowing you to set yours with no special permissions.

    Thank you to Kevin from TeslaCoil and NovaLauncher for the information on how this is done!

提交回复
热议问题