Clearing and setting the default home application

前端 未结 4 2008
情话喂你
情话喂你 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:03

    r2DoesInc's solution doesn't work on my 4.2.2 test device.
    My solution: Disable then re-enable my app's HomeActivity, it doesn't have to create FakeHome

    PackageManager p = getPackageManager();
    ComponentName cN = new ComponentName(this, HomeActivity.class);
    p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
    p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    

提交回复
热议问题