San
San

Reputation: 315

set custom launcher as default launcher by code

I am able to reset the default launcher by code with the help of following link How to reset default launcher/home screen replacement?

Now, I want to set my custom launcher as default launcher. But the following code is not working. It crashes

ComponentName componentName = new ComponentName("com.xxx.launcher", "com.xxx.launcher.LauncheActivity");

            PackageManager pm = getPackageManager();
            int flag = ((pm.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
            pm.setComponentEnabledSetting(componentName, flag, PackageManager.DONT_KILL_APP); //crash at this line..

Upvotes: 0

Views: 1745

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006674

I want to set my custom launcher as default launcher

That is not possible. The user can set your home screen as the default home screen, such as by pressing HOME and choosing your app as the default. However, you cannot force the user to accept your home screen as the default.

But the following code is not working. It crashes

That code does not set your "custom launcher as default launcher". That simply controls whether or not you are even a potential option for being a home screen (if you are disabled, you cannot possibly be the home screen).

As to why it is crashing, without a stack trace, that will be difficult to determine.

Upvotes: 1

Related Questions