Clearing and setting the default home application

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

When a component with

        <category android:name="android.intent.category.HOME" />

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.

<activity
            android:name="com.t3hh4xx0r.haxlauncher.FakeHome"
            android:enabled="false">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>     

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!

Leave a Comment